Have element of differents types in a recursive tree?

4 posts, 0 answers
  1. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 24 Aug 2010 Link to this post

    Hi!

    I've to create a tree that represent Files and Folder.

    my actual structure is:

    Folder object has
    -->SubFolder ObservableCollection
    -->File List (observablecollection too)

    I need to have in the same tree files and folder.

    I've no problem creating a treee browsing Folders:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.Resources>
            <HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding SubFolders}">
                <TextBlock Text="{Binding Name}"/>
            </HierarchicalDataTemplate>
        </Grid.Resources>
        <telerik:RadTreeView Name="uxRadTreeView" ItemsSource="{Binding RootFolder.SubFolders}" ItemTemplate="{StaticResource NodeTemplate}" AllowDrop="False" IsDragDropEnabled="True" DragEnded="uxRadTreeView_DragEnded" />
    </Grid>

    But how can I get files with that too?

    They both have a "Name" property


  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 25 Aug 2010 Link to this post

    Hello Julien,

    You just need to create an additional property (AllItems of type ObservableCollection) that contains both files and folders lists and use that property in the data binding.

    <HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding AllItems}">
        <TextBlock Text="{Binding Name}"/>
    </HierarchicalDataTemplate>

    Also, you can use ItemTemplateSelector property of the RadTreeView instead of using ItemTemplate. This way you will be able to apply different data templates to different items in the tree based on custom logic. I'm attaching a sample project demonstrating what I mean.

    Kind regards,
    Hristo Milyakov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 26 Aug 2010 Link to this post

    But I've to maintain updated theses two properties,

    And I can't open the ExpressionTree, I got a strange error: C:\Users\julien\Desktop\test\ExpressionTree\ExpressionTree.csproj : error  : Unable to read the project file 'ExpressionTree.csproj'. 

    ExpressionTree.Web hasn't this problem
  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 27 Aug 2010 Link to this post

    Hello Julien,

    Yes, you have to maintain the collections synchronized.

    The project I sent you was a Silverlight project I've attached by mistake. You can take a look at the following attachment, which is a WPF project using framework version 3.5.

    Greetings,
    Hristo Milyakov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top