1
votes

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.

1
Please, rephrase your question. Not really clear for me what are you asking... Thanks.Sergei B.
I've understood his question. He uses nested TreeView controls inside data templates and therefore it is possible to select several items. I would recommend to change the ControlTemplate of the TreeViewItem instead of the DataTemplate and use expanders there.vortexwolf
thanks for your response vorrtex. So you suggest me to have nested treeview without the use of datatemplate, expander and listwiew. It was like i hade rewrite the treeview control from scratch ! . You are saying that in case of nested treeview there will be only 1 item selected at once ?Avlin
@Avlin I tried to say that the TreeView control already contains expanders (the triangular ToggleButton on the left of each item) and there is no necessity to add additional expanders to data templates. But I would know better if you posted a screenshot of your control. Another approach: to handle selection events and when one control receives selection - the code clears selections in all other controls. But it is more difficult. Anyway add a screenshot of the control and I will try to implement it correctly.vortexwolf

1 Answers

1
votes

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