开发者

WPF color nodes based on view property

开发者 https://www.devze.com 2023-03-08 02:16 出处:网络
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 tha

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

精彩评论

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