I have a requirement in which a menu should be implemented as a treeview on the left side of a window.
I know how to populate the treeview with the (menu)data (the mvvm way).
But: how do i hook up each object in the treeview to an ICommand (in the Viewmodel)?? so that e.g. double clicking an object results in opening a window??
Thanks in advance
I think this problem should be solved in another way but…
view model as a property.
treeview item.
command property, you bind this to
your view model’s command in the
tree views itemContainerStyle (in
the xaml)
down on the tree view item to call
the command
here is a sample TreeViewItem
and a treeview to use this item
now as some smart people have said above, you would be better off using a menu and styling it. now when you double click the treeview item it will call the command instead of expanding/collapsing as it should.
this is how you would use it in the xaml