private void ClickGesture_Tapped(object sender, EventArgs e)
        {
            Clicked?.Invoke(this, e);

            if (TappedCommand != null && TappedCommand.CanExecute(CommandParameter))
            {
                TappedCommand?.Execute(CommandParameter);
            }
        }
Exemple #2
0
        public void OnTapped()
        {
            System.Diagnostics.Debug.WriteLine("{0} was tapped", Text);
            if (TappedCommand != null && TappedCommand.CanExecute(WorkoutId.ToString()))
            {
                TappedCommand.Execute(WorkoutId.ToString());
            }

            var handler = Tapped;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
        protected virtual void SetItems()
        {
            _itemsRootLayout.Children.Clear();
            _itemsRootLayout.RowDefinitions.Clear();
            _itemsRootLayout.ColumnDefinitions.Clear();

            _itemsRootLayout.RowSpacing    = Spacing;
            _itemsRootLayout.ColumnSpacing = Spacing;

            _innerSelectedCommand = new Command <View>(async view =>
            {
                if (IsAnimation)
                {
                    double targetScale = view.Scale;
                    await view.ScaleTo(targetScale * 0.9, 100);
                    await view.ScaleTo(1, 100);
                }

                if (TappedCommand?.CanExecute(view.BindingContext) ?? false)
                {
                    TappedCommand?.Execute(view.BindingContext);
                }

                SelectedItem = view.BindingContext;
            });

            if (ItemsSource == null)
            {
                return;
            }

            Device.StartTimer(TimeSpan.Zero, () =>
            {
                int rowCount = Height == -1 ? 1 : (int)Height / (ItemsHeight + Spacing);
                int colCount = Width == -1 ? 1 : (int)Width / (ItemsWidth + Spacing);

                if (ListOrientation == ScrollOrientation.Both)
                {
                    for (int i = 0; i < rowCount; i++)
                    {
                        _itemsRootLayout.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Star
                        });
                    }

                    for (int i = 0; i < colCount; i++)
                    {
                        _itemsRootLayout.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = GridLength.Star
                        });
                    }
                }

                int startIndex = 0;

                foreach (var item in ItemsSource)
                {
                    if (ListOrientation == ScrollOrientation.Horizontal)
                    {
                        _itemsRootLayout.Children.Add(GetItemView(item), startIndex, 0);
                    }
                    else if (ListOrientation == ScrollOrientation.Vertical)
                    {
                        _itemsRootLayout.Children.Add(GetItemView(item), 0, startIndex);
                    }
                    else
                    {
                        _itemsRootLayout.Children.Add(GetItemView(item), startIndex % colCount, startIndex == 0 ? 0 : startIndex / colCount);
                    }
                    startIndex++;
                }

                SelectedItem = null;

                return(false);
            });
        }