I am trying to provide a separation (margin) between the top hierarchical items in a WPF TreeView
. The problem is that I cannot figure out how to write the Style
for it to apply only to the top items and not to every item.
The code for my TreeView
looks like this:
<TreeView ItemContainerStyle="{StaticResource treeViewItemStyle}"
ItemsSource="{Binding Container.RootRules}"
KeyUp="treeView_KeyUp"
SelectedItemChanged="TreeView_SelectedItemChanged">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type me:HybridForecastRulesViewModel}"
ItemsSource="{Binding Children}">
<Border Name="bd"
...
</Border>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type me:RootRulesViewModel}"
ItemsSource="{Binding Rules}">
<Grid>
...
</Grid>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
I have a style for the treeViewItems like this:
<Style x:Key="treeViewItemStyle"
BasedOn="{StaticResource {x:Type TreeViewItem}}"
TargetType="{x:Type TreeViewItem}">
<Setter Property="Margin" Value="0,10,0,0" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
But this style applies to items of both type (RootRulesViewModel
and HybridForecastRulesViewModel
), when I would like for it to only apply to items of type RootRulesViewModel
. How can this be done?
And the icing on the cake would be for all RootRulesViewModel
items to have a top Margin
of 10, except or the first one.