protected override void OnKeyUp(KeyEventArgs e) { if (SelectionModel != null) { if (e.Key == Key.Escape) { SelectionModel.ClearSelection(); } else if (e.Key == Key.Space) { Select(); } else if (!SelectionModel.SingleSelect) { var isShiftPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift); var isCtrlPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Control); if (e.Key == Key.A && isCtrlPressed) { SelectionModel.SelectAll(); } else if (isShiftPressed) { SelectionModel.SelectRangeFromAnchor(GetGroupIndex(), RepeatedIndex); } } } base.OnKeyUp(e); }
public ListBoxPageViewModel() { Items = new ObservableCollection <string>(Enumerable.Range(1, 10000).Select(i => GenerateItem())); Selection = new SelectionModel(); Selection.Select(1); AddItemCommand = ReactiveCommand.Create(() => Items.Add(GenerateItem())); RemoveItemCommand = ReactiveCommand.Create(() => { while (Selection.SelectedItems.Count > 0) { Items.Remove((string)Selection.SelectedItems.First()); } }); SelectRandomItemCommand = ReactiveCommand.Create(() => { var random = new Random(); using (Selection.Update()) { Selection.ClearSelection(); Selection.Select(random.Next(Items.Count - 1)); } }); }
protected override void OnKeyUp(KeyEventArgs e) { var indexPath = GetIndexPath(); Debug.WriteLine("OnKeyUp:" + indexPath.ToString()); if (SelectionModel != null) { if (e.Key == Key.Escape) { SelectionModel.ClearSelection(); } else if (e.Key == Key.Space) { SelectionModel.SelectAt(indexPath); } else if (!SelectionModel.SingleSelect) { var isShiftPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift); var isCtrlPressed = Keyboard.Modifiers.HasFlag(ModifierKeys.Control); if (e.Key == Key.A && isCtrlPressed) { SelectionModel.SelectAll(); } else if (isCtrlPressed && e.Key == Key.Space) { if (SelectionModel.IsSelectedAt(indexPath).Value) { SelectionModel.DeselectAt(indexPath); } else { SelectionModel.SelectAt(indexPath); } } else if (isShiftPressed) { SelectionModel.SelectRangeFromAnchorTo(GetIndexPath()); } } } base.OnKeyUp(e); }