TreeViewItem.Expanded and EventToCommand

Jul 15, 2010 at 12:27 PM

How can I use EventToCommand and TreeViewItem.Expanded?

I've doing somehting like this... (but dosent work)

  <TreeView Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Path= MonitoredDatabases}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Queues}">

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding ServerName}" />
                        <TextBlock Text="\" />
                        <TextBlock Text="{Binding DatabaseName}" />
                    </StackPanel>

                    <HierarchicalDataTemplate.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding QueueName}" />
                        </DataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>

                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TreeViewItem.Expanded">
                    <cmd:EventToCommand Command="{Binding Path=NodeExpanded}"
                                        CommandParameter="Expanded" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TreeView>

Help really appreciated.

Thanks

Gary Howlett
Jul 24, 2010 at 7:29 AM
Edited Jul 24, 2010 at 7:29 AM

I think if you want to work with treeview in WPF/SL your best result would come from doing something like this : http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx