WPF: TreeView unable to apply Hierachical template and style at the same time
Here is what I want to do:
<TreeView>
<TreeView.Resources>
<Style TargetType="TreeViewItem" >
<Setter Property="dz:VirtualListItemBase.AutoLoad" Value="true" />
</Style>
</TreeView.Reso开发者_如何学运维urces>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Data.Nodes}" >
<Label Grid.Column="1" Grid.Row="0" Content="{Binding Data.Name}" dz:VirtualListItemBase.AutoLoad="true" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
The style part never gets applied. The HierachicalDataTemplate seems to override the initial style. I cannot use the type to apply the template since multiple types are involved. Any ideas?
Thanks
DataTemplate
has higher precedence over Style
. Try moving the DataTemplate
into the Style
as:
<Style TargetType="TreeViewItem" >
<Setter Property="dz:VirtualListItemBase.AutoLoad" Value="true" />
<Setter Property="ItemTemplate">
<Setter.Value>
<HierarchicalDataTemplate ...
</HierarchicalDataTemplate>
</Setter.Value>
</Setter>
</Style>
精彩评论