exipen wrote:
Hello, I have a TreeView using several nested HierarchicalDataTemplates as its ItemTemplate, which finally end in a DataTemplate for the deepest node level. In each node I display an image and some text. To be able to react when nodes are expanded I have created an "expanded command" which binds to an action in my ViewModel. This event works fine if I manually create a TreeView and populate it with TreeViewItems using static data. My question I hope somebody might help me with is: How do I attach this command to all items in my TreeView while using HierarchicalDataTemplates? HierarchicalDataTemplates have no "Expanded" event but I still want every item in my TreeView to be able to trigger the expanded event. My command property is attached like this <controls:TreeViewItem command:Expanded.Command="{Binding ExpandedCommand}"/> Here are some code to further explain my problem. <!-- Deepest Level --><DataTemplate x:Key="levelnNode"> <!-- Display stuff --></DataTemplate>...<!-- First Level --><common:HierarchicalDataTemplate x:Key="level1Node" ItemsSource="{Binding Children}" ItemTemplate="{StaticResource levelnNode}"> <!-- Display stuff --></common:HierarchicalDataTemplate><!-- Root Level --><common:HierarchicalDataTemplate x:Key="rootNode" ItemsSource="{Binding Children}" ItemTemplate="{StaticResource level1Node}"> <!-- Display stuff --></common:HierarchicalDataTemplate><!-- Tree View --><controls:TreeView ItemsSource="{Binding Tree}" ItemTemplate="{StaticResource rootNode}" /> How would I go about attaching my command to this set up? Thankful for any help Kind Regards, ExipenHi,I meet the the same problem,Is there anyone know how to solve the problem?thanks