Filter : When Multiple HierarchicalDataTemplate

2 posts, 0 answers
  1. Nitin Nitin
    Nitin Nitin avatar
    41 posts
    Member since:
    Apr 2010

    Posted 05 Aug 2013 Link to this post

    Hello,

    I have created a treeview with multiple HierarchicalDataTemplateas below:

    <telerik:HierarchicalDataTemplate x:Key="TrendsTVTagsChildrenTemplate" ItemTemplate="{StaticResource TVItemTemplate}"
                                                 ItemsSource="{Binding TvItem}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding TvItem.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
                 
                <telerik:HierarchicalDataTemplate x:Key="TagsTemplate" ItemTemplate="{StaticResource TrendsTVTagsChildrenTemplate}"
                                                 ItemsSource="{Binding TrendsTVTagsChildren}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding TrendsTVTagsChildren.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
                 
                <telerik:HierarchicalDataTemplate x:Key="UPSTemplate" ItemTemplate="{StaticResource TagsTemplate}"
                                                 ItemsSource="{Binding Tags}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding Tags.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
                 
                <telerik:HierarchicalDataTemplate x:Key="IceboxTemplate" ItemTemplate="{StaticResource UPSTemplate}"
                                                 ItemsSource="{Binding UPS}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding UPS.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
                 
                <telerik:HierarchicalDataTemplate x:Key="ZonesTemplate" ItemTemplate="{StaticResource IceboxTemplate}"
                                                 ItemsSource="{Binding Icebox}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding Icebox.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
                 
                <telerik:HierarchicalDataTemplate x:Key="PlantTemplate" ItemTemplate="{StaticResource ZonesTemplate}"
                                                 ItemsSource="{Binding Zones}">
                    <StackPanel Orientation="Horizontal">
                        <ContentControl ContentTemplate="{Binding Type,Converter={StaticResource TrendsIconConverter}}"></ContentControl>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="[" HorizontalAlignment="Center" />
                        <TextBlock Text="{Binding Zones.Count}" />
                        <TextBlock Text="]"  />
                    </StackPanel>
                </telerik:HierarchicalDataTemplate>
    I wanted to apply filter on key press, but the treeview itemsource contains recursive dataset 

    Is this the right way to create a treeview with various number of treeviewitems and branches

    Also I want to give treeviewitem fontcolor looking at different types of items

    thanks,
    nitin


  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 08 Aug 2013 Link to this post

    Hi Nitin,

    I am not sure that I fully understand your scenario. However, I will try to give a suggestion.

    If you need to implement hierarchical structure using the RadTreeView you can define only one HierarchicalDataTemplate in order to visualize all levels of your hierarchical collection. Please note that if you want to do this your business data must be structured like so:

    class MyBusinessDataItem
    {
        public ObservableCollection<MyBusinessDataItem> Children { get; set; }
        public Type1 Property1 { get; set; }
        public Type2 Property2 { get; set; }
        public Type3 Property3 { get; set; }
        ...
    }
    and in XAML you can define the HierarchicalDataTemplate like this:

    <telerik:HierarchicalDataTemplate x:Key="MyHierarchicalTempate" ItemsSource="{Binding Children}">
        <StackPanel>
            <TextBlock Text="{Binding Property1}" />
            <TextBlock Text="{Binding Property2}" />
            <TextBlock Text="{Binding Property3}" />
        </StackPanel>
    </telerik:HierarchicalDataTemplate>
    Furthermore, you will be able to define a property of type SolidColorBrush (or string) in your ViewModel and bind it to the Foreground property of the TextBlock from your template. Please note that the ItemTemplate property of this template is not set and in this case the already defined template will be used as ItemTemplate. This is why your business object must hold all the properties that are specific to all of the levels and items in your hierarchy.

    I hope this information will help you. If the suggested approach is not working in your scenario, please elaborate more on your requirements and your current implementation.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top