The WPF Treeview responds to + and - keystrokes to expand and collapse nodes in the tree. Great!
Is there an existing command I can bind my toolbar buttons or menu items to to perform the same actions in the treeview? I don’t see anything related to expand/collapse in the stock command constants.
The
TreeViewhandles the expansion of aTreeViewItemwith the mouse by bindingToggleButton.IsCheckedtoTreeViewItem.IsExpandedin theControlTemplateand handles expansion with the keyboard in an overrideTreeViewItem.OnKeyDown. So, no, it doesn’t use commands in its implementation.But you can add your own commands without much effort. In this example, I’ve added a behavior to a
TreeViewso that it responds to the standardOpenandCloseapplication commands:and here is the behavior that makes that work:
If you are not familiar with behaviors, first add this namespace:
and add the corresponding reference to your project.