private void HandleItemSelection(ItemClickEventArgs args) { if (SelectionMode != ListViewSelectionMode.None) { var newSelection = BindableAdapter.GetRawItem(args.Position); switch (SelectionMode) { case ListViewSelectionMode.Single: var selectedItem = BindableAdapter.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)) { BindableAdapter.SetItemSelection(selectedItem, null, false); } if (selectedItem != newSelection) { BindableAdapter.SetItemSelection( newSelection, (args.View as ItemContainerHolder)?.Child as SelectorItem, true ); } SelectedItem = newSelection; break; case ListViewSelectionMode.Multiple: BindableAdapter.SetItemSelection( BindableAdapter.GetRawItem(args.Position), args.View as SelectorItem, !BindableAdapter.SelectedItems.Contains(newSelection) ); break; } SelectedItems = BindableAdapter.SelectedItems.ToArray(); } }
private void UpdateSelection(IList <object> newSelection) { if (BindableAdapter != null) { if (!BindableAdapter.SelectedItems.SequenceEqual(newSelection)) { var removed = BindableAdapter .SelectedItems .Except(newSelection) .ToArray(); var added = newSelection .Except(BindableAdapter.SelectedItems) .ToArray(); removed.ForEach((object i) => BindableAdapter.SetItemSelection(i, null, false)); added.ForEach((object i) => BindableAdapter.SetItemSelection(i, null, true)); } } }
private void UpdateSelection(object[] oldSelection, object[] newSelection) { if (BindableAdapter != null) { if (!BindableAdapter.SelectedItems.SequenceEqual(newSelection)) { var removed = BindableAdapter .SelectedItems .Except(newSelection) .ToArray(); var added = newSelection .Except(BindableAdapter.SelectedItems) .ToArray(); removed.ForEach((object i) => BindableAdapter.SetItemSelection(i, null, false)); added.ForEach((object i) => BindableAdapter.SetItemSelection(i, null, true)); } } SelectionChanged?.Invoke(this, new SelectionChangedEventArgs(oldSelection, newSelection)); }