コード例 #1
0
ファイル: ListView.Android.cs プロジェクト: unoplatform/uno
        private void OnItemClick(object sender, ItemClickEventArgs args)
        {
            if (IsItemClickEnabled)
            {
                ExecuteCommandOnItem(ItemClickCommand, args.Position);
            }

            ItemClick?.Invoke(this, new Windows.UI.Xaml.Controls.ItemClickEventArgs {
                ClickedItem = ListViewAdapter.GetItemAt(args.Position)
            });

            HandleItemSelection(args);
        }
コード例 #2
0
ファイル: ListView.Android.cs プロジェクト: unoplatform/uno
        private void HandleItemSelection(ItemClickEventArgs args)
        {
            if (SelectionMode != ListViewSelectionMode.None)
            {
                var newSelection = ListViewAdapter.GetItemAt(args.Position);

                switch (SelectionMode)
                {
                case ListViewSelectionMode.Single:
                    var selectedItem = ListViewAdapter.SelectedItems.FirstOrDefault();

                    // Unselect the current item only if a new selection is made or
                    // the option to unselect the current item is activated.
                    if (selectedItem != null && (selectedItem != newSelection || UnselectOnClick))
                    {
                        ListViewAdapter.SetItemSelection(selectedItem, null, false);
                    }

                    if (selectedItem != newSelection)
                    {
                        ListViewAdapter.SetItemSelection(
                            newSelection,
                            (args.View as ItemContainerHolder)?.Child as SelectorItem,
                            true
                            );
                    }

                    SelectedItem = newSelection;

                    if (selectedItem != newSelection)
                    {
                        SelectionChanged?.Invoke(this, new SelectionChangedEventArgs(this, new[] { selectedItem }, new[] { newSelection }));
                    }
                    break;

                case ListViewSelectionMode.Multiple:
                    ListViewAdapter.SetItemSelection(
                        ListViewAdapter.GetItemAt(args.Position),
                        args.View as SelectorItem,
                        !ListViewAdapter.SelectedItems.Contains(newSelection)
                        );
                    break;
                }

                SelectedItems = ListViewAdapter.SelectedItems.ToArray();
            }
        }
コード例 #3
0
ファイル: ListView.Android.cs プロジェクト: unoplatform/uno
        protected void ExecuteCommandOnItem(ICommand command, int position)
        {
            if (command == null)
            {
                return;
            }

            var item = ListViewAdapter.GetItemAt(position);

            if (item == null)
            {
                return;
            }

            if (!command.CanExecute(item))
            {
                return;
            }

            command.Execute(item);
        }