c# - 如何展平 WPF TreeView

标签 c# wpf mvvm treeview grid

我需要一个行为类似于 TreeView 的控件(绑定(bind)到树结构,根据绑定(bind)对象的 IsExpanded 属性展开子节点),但显示数据类似于网格(无缩进或切换图像)。

展开折叠将根据绑定(bind)对象自动发生。

TreeView 是完美的,我只需要删除缩进和三角形图像,使其垂直平坦,就像一个网格列。

我想我可以尝试覆盖 TreeViewItem 模板,但那只是不显示任何内容..

最佳答案

基于TreeView style on MSDN ,这样的事情应该有效:

<Style TargetType="TreeViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TreeViewItem">
                <StackPanel>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ExpansionStates">
                            <VisualState x:Name="Expanded">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetProperty="(UIElement.Visibility)"
                                        Storyboard.TargetName="ItemsHost">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                            Value="{x:Static Visibility.Visible}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Collapsed" />
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentPresenter ContentSource="Header" />
                    <ItemsPresenter Name="ItemsHost" Visibility="Collapsed" />
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

关于c# - 如何展平 WPF TreeView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7563771/

相关文章:

c# - 如何在中继命令中获取Listview Item点击值

c# - 能够在用户尝试关闭 Windows 窗体而不保存时通知用户请求 'Save Changes'

wpf - WPF RichTextBox 中的段落格式?

c# - 不区分大小写的搜索 C#

c# - MVVM使用命令混淆将更改保存到 View 模型

c# - 如何在 View 模型中的 View 上使用路由命令

c# - 比较两个列表并删除相同的结果c#

c# - 我们如何在不重新插入列表框的情况下刷新项目文本?

c# - 从 C# 中的列表中完全删除所有至少有一个重复项的元素

c# - Caliburn Micro Action