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

No data when using MVVM

1 Answer 80 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Fredrik asked on 30 Apr 2020, 11:34 AM

I'v tried to follow a few of the how to do it but I do not get any data in my controller.

The code below is my latest attempt. If I create RadTreeViewItems in my ViewModel and then set them directly to the ItemsSource the treview is populated.

Can anyone see if I am missing something?


        <viewmodels:FilterViewModel x:Key="FVM" />

        <DataTemplate x:Key="QualifierHDT"
                      DataType="{x:Type models:Qualifier}">
            <TextBlock Text="{Binding Name}" />
        <HierarchicalDataTemplate x:Key="ComponentHDT"
                                  DataType="{x:Type models:Component}"
                                  ItemsSource="{Binding Components}"
                                  ItemTemplate="{StaticResource QualifierHDT}">
            <TextBlock Text="{Binding Name}" />

        <HierarchicalDataTemplate x:Key="SystemCollectionHDT"
                                  DataType="{x:Type models:SystemCollection}"
                                  ItemsSource="{Binding SystemCollections}"
                                  ItemTemplate="{StaticResource ComponentHDT}">
            <TextBlock Text="{Binding Name}" />

        <HierarchicalDataTemplate x:Key="BuildingHDT"
                                  DataType="{x:Type models:Building}"
                                  ItemsSource="{Binding Buildings}"
                                  ItemTemplate="{StaticResource SystemCollectionHDT}">
            <TextBlock Text="{Binding Name}" />

        <HierarchicalDataTemplate x:Key="AreaHDT"
                                  DataType="{x:Type models:Area}"
                                  ItemsSource="{Binding Areas}"
                                  ItemTemplate="{StaticResource BuildingHDT}">
            <TextBlock Text="{Binding Name}" />

        <Style x:Key="ItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="IsSelected" Value="{Binding Path=Selected}"/>
            <Setter Property="IsExpanded" Value="{Binding Path=Expanded}"/>
        <helpers:FilterViewTemplateSelector x:Key="myDataTemplateSelector"
                                            AreaTemplate="{StaticResource AreaHDT}"
                                            BuildingTemplate="{StaticResource BuildingHDT}"
                                            SystemCollectionTemplate="{StaticResource SystemCollectionHDT}"
                                            ComponentTemplate="{StaticResource ComponentHDT}"
                                            QualifierTemplate="{StaticResource QualifierHDT}"/>


 <telerik:RadTreeView MinWidth="200px"
                             ItemsSource="{Binding Source={StaticResource FVM}}"
                             ItemTemplate="{StaticResource AreaHDT}"
                             ItemContainerStyle="{StaticResource ItemContainerStyle}"
                             ItemTemplateSelector="{StaticResource myDataTemplateSelector}">


Class structure

Class  Area

string Name;

ICollection<Building> buildings


Class Building

string Name:

ICollection<SystemCollection> SystemCollections


Class SystemCollection

string Name;

ICollection<Componennt> Components


Class Component

string Name;

ICollection<Qualifier> Qualifiers


Class Qualifier

String Name;



1 Answer, 1 is accepted

Sort by
Vladimir Stoyanov
Telerik team
answered on 05 May 2020, 07:06 AM

Hello Fredrik,

Thank you for the shared code snippets. 

Looking at them, the ItemsSource of the RadTreeView points directly to the "FilterViewModel". While I am not sure how it is defined, I am assuming that it contains a collection of the "first-level" objects. If that is the case, you should point the ItemsSource binding to the corresponding property. To debug such scenarios you can check for binding errors in the Output Window of Visual Studio. 

Another thing that I noticed is that both the ItemTemplate and the ItemTemplateSelector properties are set. Note, that the two of them are redundant and only the ItemTemplate will be respected.

Should you need any further assistance, you can share a sample project in a new support ticket (since project files cannot be attached to forum posts) and I will be glad to investigate the scenario.

Vladimir Stoyanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Asked by
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question