I h开发者_JS百科ave a WPF treeview that I would like the color of a node to be based on a particular getter. I can't figure how to databind for that case. I would like it to look like this except that odd numbers would be a child node of the even numbers
If you already use HierarchicalDataTemplate
, you can simply add a trigger:
<TreeView ItemsSource="{Binding}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Highlight}" Value="True">
<Setter Property="Background" Value="Yellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
精彩评论