public void ClearMultipleSelection() { foreach (object item in Items) { TreeViewItemEx ex = ItemContainerGenerator.ContainerFromItem(item) as TreeViewItemEx; ex?.ClearMultipleSelection(); } }
private static void DoBringIntoViewChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TreeViewItemEx ex = d as TreeViewItemEx; if (ex?.ParentTreeView != null && (bool)e.NewValue) { ex.ParentTreeView.BringIntoViewHandled = false; ex.BringIntoView(); ex.ParentTreeView.BringIntoViewHandled = true; ex.DoBringIntoView = false; } }
protected override void OnSelected(RoutedEventArgs e) { base.OnSelected(e); RequestBringIntoView += TreeViewItemEx_RequestBringIntoView; if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { ItemsControl items = ParentItemsControl; bool hasMultipleSelected = false; foreach (object item in items.Items) { TreeViewItemEx ex = items.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItemEx; if (ex != null && ex.IsMultipleSelected) { hasMultipleSelected = true; break; } } if (hasMultipleSelected) { ParentTreeView.HandlingMultipleSelected = true; bool select = false; foreach (object item in items.Items) { TreeViewItemEx ex = items.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItemEx; if (ex == null) { continue; } if (select) { if (ReferenceEquals(ex, this) || ex.IsMultipleSelected) { ex.IsMultipleSelected = true; break; } ex.IsMultipleSelected = true; } else { if (ReferenceEquals(ex, this) || ex.IsMultipleSelected) { ex.IsMultipleSelected = true; select = true; } } } } } else { ParentTreeView?.ClearMultipleSelection(); IsMultipleSelected = true; if (ParentTreeView != null) { ParentTreeView.HandlingMultipleSelected = true; } } }