Ejemplo n.º 1
0
        protected override bool HandleControlStateOnTouch(Touch touch)
        {
            if (!IsEnabled || null == touch)
            {
                return(false);
            }

            PointStateType state = touch.GetState(0);

            switch (state)
            {
            case PointStateType.Down:
                IsPressed = true;
                UpdateState();
                return(true);

            case PointStateType.Interrupted:
                IsPressed = false;
                UpdateState();
                return(true);

            case PointStateType.Up:
            {
                bool clicked = IsPressed && IsEnabled;
                IsPressed = false;

                if (!clicked)
                {
                    return(true);
                }

                if (IsSelectable)
                {
                    if (ParentItemsView as CollectionView)
                    {
                        CollectionView colView = ParentItemsView as CollectionView;
                        switch (colView.SelectionMode)
                        {
                        case ItemSelectionMode.SingleSelection:
                            colView.SelectedItem = IsSelected ? null : BindingContext;
                            break;

                        case ItemSelectionMode.MultipleSelections:
                            var selectedItems = colView.SelectedItems;
                            if (selectedItems.Contains(BindingContext))
                            {
                                selectedItems.Remove(BindingContext);
                            }
                            else
                            {
                                selectedItems.Add(BindingContext);
                            }
                            break;

                        case ItemSelectionMode.None:
                            break;
                        }
                    }
                }
                else
                {
                    // Extension : Extension?.SetTouchInfo(touch);
                    UpdateState();
                }

                if (clicked)
                {
                    ClickedEventArgs eventArgs = new ClickedEventArgs();
                    OnClickedInternal(eventArgs);
                }

                return(true);
            }

            default:
                break;
            }
            return(base.HandleControlStateOnTouch(touch));
        }