protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (ParentMultipleSelectionTreeView == null) { return; } /* * if (ParentMultipleSelectionTreeView.SelectionMode == SelectionModalities.KeyboardModifiersMode) * { * if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl)) * return; * } */ if (!this.IsSelected) { this.IsSelected = true; } else { this.IsSelected = false; } ParentMultipleSelectionTreeView.OnViewItemMouseDown(this); //prevent parent node from being selected e.Handled = true; }
/// <summary> /// Recursively select all children. /// </summary> public void SelectAllExpandedChildren() { if (Items != null && Items.Count > 0) { if (this.IsExpanded) { foreach (var item in Items) { if (item is MSTreeViewItem) { ((MSTreeViewItem)item).SelectAllExpandedChildren(); } else { MSTreeViewItem tvItem = this.ItemContainerGenerator.ContainerFromItem(item) as MSTreeViewItem; if (tvItem != null) { tvItem.SelectAllExpandedChildren(); } } } } } if (!this.IsSelected) { this.IsSelected = true; ParentMultipleSelectionTreeView.OnSelectionChanges(this); } }
public void Select() { this.IsSelected = true; ParentMultipleSelectionTreeView.OnSelectionChanges(this); }
protected override void OnKeyDown(KeyEventArgs e) { try { MSTreeViewItem itemToSelect = null; if (e.Key == Key.Left) { this.IsExpanded = false; } else if (e.Key == Key.Right) { this.IsExpanded = true; } else if (e.Key == Key.Up) { // In this case we need to select the last child of the last expandend node of // - the previous at the same level (if this index node is NOT 0) // - the parent node (if this index node is 0) int currentNodeIndex = this.ParentItemsControl.ItemContainerGenerator.IndexFromContainer(this); if (currentNodeIndex == 0) { itemToSelect = this.ParentMultipleSelectionTreeViewItem; } else { MSTreeViewItem tmp = null; tmp = GetPreviousNodeAtSameLevel(this); itemToSelect = GetLastVisibleChildNodeOf(tmp); } } else if (e.Key == Key.Down) { // In this case we need to select: // - the first child node (if this node is expanded) // - the next at the same level (if this not the last child) // - the next at the same level of the parent node (if this is the last child) if (this.IsExpanded && this.Items.Count > 0) { // Select first Child itemToSelect = this.ItemContainerGenerator.ContainerFromIndex(0) as MSTreeViewItem; } else { itemToSelect = GetNextNodeAtSameLevel(this); if (itemToSelect == null) // current node has no subsequent node at the same level { MSTreeViewItem tmp = this.ParentMultipleSelectionTreeViewItem; while (itemToSelect == null && tmp != null) // searhing for the first parent that has a subsequent node at the same level { itemToSelect = GetNextNodeAtSameLevel(tmp); tmp = tmp.ParentMultipleSelectionTreeViewItem; } } } } if (itemToSelect != null) { itemToSelect.Focus(); itemToSelect.IsSelected = true; ParentMultipleSelectionTreeView.OnViewItemMouseDown(itemToSelect); } } catch (Exception) { /* Silently ignore */ } // Don't bubble up the event. (I'm sure you know difference between Bubble and Tunnel events in WPF...) e.Handled = true; }