【发布时间】:2012-01-26 18:40:57
【问题描述】:
我有一些分层数据需要显示为表格,我可以更改 TreeView 的样式以类似列表的方式显示数据吗?
所以而不是:
+Group1
SubItem1
SubItem2
+Group2
+Group
SubItem11
SubItem12
我想要这个:
Group1
SubItem1
SubItem2
Group2
Group
SubItem11
SubItem12
我的代码如下所示:
<TreeView ItemsSource="{Binding RootItems}"
dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="true" />
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type vm:CategoryViewModel}"
ItemsSource="{Binding Children}">
<v:Category DataContext="{Binding}" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type vm:ItemViewModel}">
<v:Item DataContext="{Binding}" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
我知道我应该能够使用 TreeView 的样式,但我不知道从哪里开始,而且我找不到这方面的任何信息。
【问题讨论】:
-
所以基本上你想完全扁平化层次结构?或者你想要层次结构的不同级别有不同的样式?
-
是的,我想扁平化层次结构
标签: wpf treeview wpf-controls