树视图与嵌套扩展器

发布于 2024-12-06 19:15:36 字数 2190 浏览 0 评论 0原文

编辑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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2024-12-13 19:15:36

通过使用项目容器样式选择器,您可以拥有 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文