I am trying to implement Multi-Select with Multi-Level WPF Tree View. For this , I disabled the WPF selection and, instead highlighted the selected items and processed it.
This implementation works fine for Ctrl button and select random .
But for shift select if I try to highlight Tree Node which is not expanded , I can highlight Tree Node but not its children. Requirement is to expand Tree Node and highlight children too.
I am not able to get container for children node from ItemContainerGenerator after expanding Tree Node.It returns null always
Whatever I tried till now
1.Use UpdateLayout() after expanding Parent TreeViewItem; (ItemContainerGenerator.ContainerFromItem(item) return null)
- Turn off VirtualizationStack.
Is there any way to make ItemContainerGenerator generate items instataneously after expanding TreeNode
Any help is appreciated!!!
You should not operate on the item containers but on the items.
To do so, you need to add a
IsSelectedproperty to your model. You also need to select the child items of a node.In order to register a
MouseBindingon theTreeViewItemyou would have to override the defaultControlTemplateofTreeViewItem. TheMouseBindingdefines aMouseGestureto trigger on "CTRL + LeftClick". AICommandregistered with theMouseBindingexecutes the actual selection of the item by toggling theIsSelectedproperty.To get the selected items you simply iterate over the source collection (traverse the tree structure) to collect all items where
IsSelectedequalstrue.TreeItem.cs
ViewModel.cs
MainWindow.xaml