This is a migrated thread and some comments may be shown as answers.

Horizontal Orientation at the one level only

1 Answer 65 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Dipti asked on 12 Jan 2012, 11:26 AM

I have a treeview which has vertical orientation at all levels except the first level (i.e. one level from root). I have not defined my treeview items in XAML, the data is loaded through C# (i.e. RadTreeViewItems are generated dynamically). 

I want that Counties and Regions should have vertical orientation whereas Continents should have horizontal orientation.

-All Regions
    -Continent1                        -Continent2
            - Region1                           -Region2 
                -Country1                          -Country5 
                -Country2                          -Country6
                -Country3                           -Country7      
                -Country4                           -Country9
                -Country8                           -Country10
            - Region4                            -Region3
                -Country1                            -Country2      
                -Country3                            -Country4      
                -Country5                            -Country6
                -Country7                            -Country8      
            - Region5                            -Region6
                -Country11                            -Country12      
                -Country13                            -Country14  

Is this possible when we are using HierarchicalDataTemplate?

Please see my code below.

<telerik:HierarchicalDataTemplate x:Key="allRegionsTemplate" 
    ItemsSource="{Binding Continents}" 
    telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
    <TextBlock Text="{Binding Name}"/>
<telerik:HierarchicalDataTemplate x:Key="continentTemplate" 
        ItemsSource="{Binding Regions}" 
        telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
        <StackPanel Orientation="Horizontal"
            <TextBlock Text="{Binding Name}"/> 
    <telerik:HierarchicalDataTemplate x:Key="regionTemplate" 
        ItemsSource="{Binding Countries}" 
        telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
        <TextBlock Text="{Binding Name}"/> 
    <DataTemplate x:Key="countryTemplate" 
        telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"
        <TextBlock Text="{Binding Name}"/> 
    <local:ThreeLevelTemplateSelector x:Key="ThreeLevelTemplateSelector" 
         AllRegionsTemplate="{StaticResource allRegionsTemplate}"
       ContinentTemplate="{StaticResource continentTemplate}"
        RegionTemplate="{StaticResource regionTemplate}"
        CountryTemplate="{StaticResource countryTemplate}" /> 
<telerikNavigation:RadTreeView x:Name="treeView" Grid.Column="1" Grid.Row="1"
 ItemTemplateSelector="{StaticResource ThreeLevelTemplateSelector}" 
 Unchecked="treeView_Unchecked" />

The Data is loaded from C# using a list:
this.treeView.ItemsSource = List;


1 Answer, 1 is accepted

Sort by
Petar Mladenov
Telerik team
answered on 17 Jan 2012, 09:43 AM
Hi Dipti,

 I prepared a solution for you which demonstrates a possible approach. Basically, I have a boolean property in My ViewModel that is bound to the Style property of the RadTreeViewItem via converter. When it is se to True, the corresponding Style sets Horizontal StackPanel for the ItemsPanelTemplate of the RadTreeViewItem.
Please let us know if you need further assistance.

All the best,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Asked by
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question