开发者

WPF color nodes based on view property

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜