tags:

views:

289

answers:

1

Hi.

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, then 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#.

+1  A: 

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.

David Hay
Confused, do what?I'm pretty new at WPF
James J
I edited to indicate a little better.
David Hay
hmm.. that makes a little more sense, but do you know how i would pass in the commandParameter of the item it is clicking?Like, if you wanted to open a specific file, then when you click the treeView, then it would pass in the file's id and open it based on the id.
James J