TreeView, Overiding the double click mouse event WPF
I was wondering, what will be the best way to override the Tree View's mouse click? As you know when you double click a tree view parent, th开发者_StackOverflowen the tree view expands and shows the children. If it doesn't have any children then it doesn't do anything. but if it is already expanded, it will the collapse.
I want to take the tree view, and when you double click the children, it will bind to some sort of command.
So basically, i would like to keep the functionality of the parent, where you double click and it expands or collapses, but when you double click the Child, it will execute a certain command..
I am using XAML and C#.
Remember that events bubble in WPF, so you can have an event handler on double click to do your own thing -- and as long as you don't set RoutedEventArgs.Handled to true it will keep bubbling and should trip off the default behavior as well.
Specifically, just set up a handler for MouseDoubleClick on the treeview:
<TreeView MouseDoubleClick="TreeView1_MouseDoubleClick" Width="194" Height="200">
...
</TreeView>
Do whatever you need to do inside the handler, and the double click to expand/contract functionality of the treeview won't be impacted.
精彩评论