public void Select(bool select) { if (SelectionModel != null) { var indexPath = GetIndexPath(); if (select) { SelectionModel.SelectAt(indexPath); } else { SelectionModel.DeselectAt(indexPath); } } }
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); }
public PageViewModel() { Node root = new Node(); Items = root.Children; Selection = new SelectionModel(); AddItemCommand = ReactiveCommand.Create(() => { Node parentItem = Selection.SelectedItems.Count > 0 ? (Node)Selection.SelectedItems[0] : root; parentItem.AddNewItem(); }); RemoveItemCommand = ReactiveCommand.Create(() => { while (Selection.SelectedItems.Count > 0) { Node lastItem = (Node)Selection.SelectedItems[0]; RecursiveRemove(Items, lastItem); Selection.DeselectAt(Selection.SelectedIndices[0]); } bool RecursiveRemove(ObservableCollection <Node> items, Node selectedItem) { if (items.Remove(selectedItem)) { return(true); } foreach (Node item in items) { if (item.AreChildrenInitialized && RecursiveRemove(item.Children, selectedItem)) { return(true); } } return(false); } }); }