我需要一个行为类似于 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/