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

Load data from Dictionary

2 Answers 359 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Fredrik
Top achievements
Rank 1
Veteran
Iron
Fredrik asked on 11 Sep 2020, 12:29 PM

I have a nested Dictionary with 5 levels.

I would like to show it in the TreeView but I only get the first layer.

<telerik:RadTreeView x:Name="myTreeView"
                             MinWidth="200px"
                             ItemsSource="{Binding Areas}"
                             ItemTemplate="{StaticResource BuildingHDT}"
                             ItemContainerStyle="{StaticResource ItemContainerStyle}"
                             MaxHeight="{Binding ElementName=host, Path=ActualHeight}"
                             Grid.IsSharedSizeScope="True"
                             HorizontalContentAlignment="Stretch"
                             IsVirtualizing="True"
                             TextSearch.TextPath="Value.Name"
                             extension:ContextMenuBehavior.ContextMenu="{Binding ElementName=TreeContextMenu}">

            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="TreeContextMenu"/>
            </telerik:RadContextMenu.ContextMenu>

            <telerik:EventToCommandBehavior.EventBindings>
                <telerik:EventBinding Command="{Binding OpenSelectedItem}"
                                      EventName="MouseLeftButtonDown"
                                      RaiseOnHandledEvents="True"
                                      PassEventArgsToCommand="True" />
            </telerik:EventToCommandBehavior.EventBindings>

        </telerik:RadTreeView>

 

<HierarchicalDataTemplate x:Key="QualifierHDT"
                                  DataType="{x:Type models:Qualifier}"
                                  ItemsSource="{Binding Qualifier}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Value.Name}" />
                <TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate x:Key="ComponentHDT"
                                  DataType="{x:Type models:Component}"
                                  ItemsSource="{Binding Component}"
                                  ItemTemplate="{StaticResource QualifierHDT}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Key}" />
                <TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate x:Key="SystemCollectionHDT"
                                  DataType="{x:Type models:SystemCollection}"
                                  ItemsSource="{Binding SystemCollection}"
                                  ItemTemplate="{StaticResource ComponentHDT}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Value.Name}" />
                <TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <HierarchicalDataTemplate x:Key="BuildingHDT"
                                  DataType="{x:Type models:Building}"
                                  ItemsSource="{Binding Buildings}"
                                  ItemTemplate="{StaticResource SystemCollectionHDT}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Value.Name}" />
                <TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />
            </StackPanel>
        </HierarchicalDataTemplate>

2 Answers, 1 is accepted

Sort by
0
Fredrik
Top achievements
Rank 1
Veteran
Iron
answered on 14 Sep 2020, 08:20 AM

What was missing was adding .Values after the objects in item source.

For example:

ItemsSource="{Binding Areas}" should be ItemsSource="{Binding Areas.Values}" and ItemsSource="{Binding Buildings}" should be ItemsSource="{Binding Buildings.Values}" and so on.

0
Fredrik
Top achievements
Rank 1
Veteran
Iron
answered on 14 Sep 2020, 08:21 AM

Also

<TextBlock Text="{Binding Value.Name}" />
<TextBlock Text="{Binding Value.AnnotationCount}" Margin="5 0 0 0" />

Should be

<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding AnnotationCount}" Margin="5 0 0 0" />

Tags
TreeView
Asked by
Fredrik
Top achievements
Rank 1
Veteran
Iron
Answers by
Fredrik
Top achievements
Rank 1
Veteran
Iron
Share this question
or