I'm using code from here: WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?, from accepted answer. My xaml is like this:
<TreeView CommandBehaviors:MouseDoubleClick.Command="{Binding ConnectServer}" CommandBehaviors:MouseDoubleClick.CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Self}}"
Grid.Column="0" HorizontalAlignment="Stretch" DockPanel.Dock="Left" ItemsSource="{Binding Path=ServerItems, UpdateSourceTrigger=PropertyChanged}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="CommandBehaviors:MouseDoubleClick.Command" Value="{Binding ConnectDb}"/>
<Setter Property="CommandBehaviors:MouseDoubleClick.CommandParameter" Value="{Binding Path=SelectedItem, RelativeSource={RelativeSource Self}}"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Databases}">
<TextBlock Text="{Binding}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Attached command from Style tag does not work, and it should't since there is already a command attached on the TreeView tag level. What I'm trying to do is to execute one command for top level children, and another for lower level children. How do I do that?
EDIT:
So, as Viv suggested - how do I check if treeviewitem is a root node?