树视图与嵌套扩展器
编辑2:
这就是我只想用1个树视图做的事情:
我的带有 Outlook 风格的树视图 http://img204.imageshack.us/img204/8218/sansreju.jpg
编辑:
我想知道如何根据级别制作具有不同扩展样式的树视图。我目前使用嵌套扩展器。
原始问题:
我试图获得一个在级别方面具有不同扩展器样式的 WPF Treeview。
我实际上拥有的是:
一个列表视图,其中通过使用选择器在对象类型方面包含不同的模板
<ListView Name="MyTreeView" ItemTemplateSelector="{StaticResource Selector}">
<!-- Items Template -->
<HierarchicalDataTemplate x:Key="ItemsTemplate" ItemsSource="{Binding Childrens}">
<TextBlock Text="{Binding Name}" Margin="5,0" VerticalAlignment="Center"/>
</HierarchicalDataTemplate>
<!-- SubNode Template -->
<DataTemplate x:Key="SubNodeTemplate">
<Expander Style="{StaticResource SubExpander}">
<TreeView ItemsSource="{Binding Childrens}"
ItemTemplateSelector="{StaticResource Selector}"/>
</Expander>
</DataTemplate>
<!-- Node Template -->
<DataTemplate x:Key="NodeTemplate">
<Expander Style="{StaticResource MainViewExpander}">
<ListView ItemsSource="{Binding Childrens}"
ItemTemplateSelector="{StaticResource Selector}"/>
</Expander>
</DataTemplate>
,这是用于映射的对象背后的代码: 我得到了一个列表(IUpSlideItem)并将其应用到 MyTreeview.ItemsSource
Public Interface IUpSlideItem
Property Childrens As List(Of IUpSlideItem)
Property Name As String
End Interface
Public Class Item
Implements IUpSlideItem
Public Property Childrens As System.Collections.Generic.List(Of IUpSlideItem) Implements IUpSlideItem.Childrens
Public Property Name As String Implements IUpSlideItem.Name
End Class
Public Class Node
Implements IUpSlideItem
Public Property Childrens As System.Collections.Generic.List(Of IUpSlideItem) Implements IUpSlideItem.Childrens
Public Property Name As String Implements IUpSlideItem.Name
End Class
现在的问题是知道是否只有 1 个具有不同扩展器样式的树视图(就类型的项目而言)是可能的。我需要这个,因为我只想选择单个项目。
Edit 2 :
This is what i want to do with only 1 treeview :
my treeview with outlook style http://img204.imageshack.us/img204/8218/sansreju.jpg
Edit :
I want to know how make a treeview with different expander styles in terms of the level. I currently use nested expanders.
Original question :
I am trying to get a WPF Treeview that has differents expanders styles in terms of the level.
What i actually have is that :
a listview wich contains differents templates in term of the ojbect type by using a selector
<ListView Name="MyTreeView" ItemTemplateSelector="{StaticResource Selector}">
<!-- Items Template -->
<HierarchicalDataTemplate x:Key="ItemsTemplate" ItemsSource="{Binding Childrens}">
<TextBlock Text="{Binding Name}" Margin="5,0" VerticalAlignment="Center"/>
</HierarchicalDataTemplate>
<!-- SubNode Template -->
<DataTemplate x:Key="SubNodeTemplate">
<Expander Style="{StaticResource SubExpander}">
<TreeView ItemsSource="{Binding Childrens}"
ItemTemplateSelector="{StaticResource Selector}"/>
</Expander>
</DataTemplate>
<!-- Node Template -->
<DataTemplate x:Key="NodeTemplate">
<Expander Style="{StaticResource MainViewExpander}">
<ListView ItemsSource="{Binding Childrens}"
ItemTemplateSelector="{StaticResource Selector}"/>
</Expander>
</DataTemplate>
And this is the code behind with object used for mapping :
I got a list (of IUpSlideItem ) and apply it to MyTreeview.ItemsSource
Public Interface IUpSlideItem
Property Childrens As List(Of IUpSlideItem)
Property Name As String
End Interface
Public Class Item
Implements IUpSlideItem
Public Property Childrens As System.Collections.Generic.List(Of IUpSlideItem) Implements IUpSlideItem.Childrens
Public Property Name As String Implements IUpSlideItem.Name
End Class
Public Class Node
Implements IUpSlideItem
Public Property Childrens As System.Collections.Generic.List(Of IUpSlideItem) Implements IUpSlideItem.Childrens
Public Property Name As String Implements IUpSlideItem.Name
End Class
Now the question is to know if only 1 treeview with different expander style in terms of the type's item is possible. I need this because i want single item select only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用项目容器样式选择器,您可以拥有 1 个具有不同扩展器样式的树视图:
http://msdn.microsoft.com/fr-fr/library/system.windows.hierarchicaldatatemplate.itemcontainerstyleselector%28v=vs.90%29.aspx
编辑:此解决方案有效,我现在有一个完美的 TreeView
by using an item container style selctor you can have 1 treeview with different expander style :
http://msdn.microsoft.com/fr-fr/library/system.windows.hierarchicaldatatemplate.itemcontainerstyleselector%28v=vs.90%29.aspx
edit : this solution is working, i have a perfect TreeView now