problem on second level visualization

Good morning,

for the first time i'm trying to develop a project using .Net 10, WPF and VisualBasic on VisualStudio 2026. I created a Viewmodel with an observable collection (ListaCommDaInserire) of "Comm" and each "Comm" has an observable collection (ListaSubComm) of "SubComm". This list is part of the main viemodel "CommesseDaInserire" that is the datacontext of the window:

 <Window.DataContext>

     <local:VM_CommesseDaInserire />

 </Window.DataContext>

The main collection is created as expected and i want to visualize it using a SfTreeview with HierarchicalDataTemplate but here comes the problem. The first level is correctly rendered while the second level appears but without showing the data. Below You can see how i'm trying to create the SfTreeview and its datatemplates:

<syncfusion:SfTreeView Name="SFTW_Comm" ItemsSource="{Binding ListaCommDaInserire}" ChildPropertyName="ListaSubComm" >

    <syncfusion:SfTreeView.Resources>

        <DataTemplate DataType="{x:Type local:SubComm}">

            <StackPanel Orientation="Horizontal">

                <CheckBox IsChecked="{Binding Selezionata}"/>

                <Label Content="{Binding CommCliente}"/>

            </StackPanel>

        </DataTemplate>


        <HierarchicalDataTemplate x:Key="CommTemplate" DataType="{x:Type local:CommDaInserire}" ItemsSource="{Binding ListaSubComm}" >

            <StackPanel Orientation="Horizontal">

                <CheckBox IsChecked="{Binding Selezionata}"/>

                <Label Content="{Binding CommTecnel}"/>

            </StackPanel>


        </HierarchicalDataTemplate>

    </syncfusion:SfTreeView.Resources>


    <syncfusion:SfTreeView.ItemTemplate>

        <StaticResource ResourceKey="CommTemplate"/>

    </syncfusion:SfTreeView.ItemTemplate>

</syncfusion:SfTreeView>

please find attched the class files.

Please help me...

Thank you in advance

Best regards



 


Attachment: CommDaInserire_de5b27dc.zip

1 Reply

SR Senthilkumar Ranganathan Syncfusion Team March 2, 2026 01:58 PM UTC

Hi marco del frate,

We have reviewed your query. Currently, SfTreeView does not directly support loading data using HierarchicalDataTemplate. So, we have already considered this requirement "Provide HierarchicalDataTemplate support in SfTreeView" as a feature from our end, but we do not have any immediate plans to implement this feature.

The status of implementation can be tracked through the feedback portal link below: Provide HierarchicalDataTemplate support in SfTreeView in WPF | Feedback Portal

Any relevant updates regarding the feature's implementation will be communicated to you through the feedback link.

However, you can populate the control by creating a hierarchical data model and binding it to the SfTreeView. You can also use HierarchyPropertyDescriptor along with the hierarchical data model.

 
Alternatively, you can use an ItemTemplateSelector to define different templates for parent and child nodes. In our sample, we have achieved your requirement using the ItemTemplateSelector, where we set the template based on the type (class) of each item.


Code snippet for setting template using ItemTemplateSelector:

MainWindow.xaml
<syncfusion:SfTreeView Name="SFTW_Comm"
                       ItemsSource="{Binding ListaCommDaInserire}"
                       ChildPropertyName="ListaSubComm"
                       ItemTemplateSelector="{StaticResource CommTreeTemplateSelector}"/>

MainWindow.xaml.vb
Public Class CommTreeTemplateSelector
    Inherits DataTemplateSelector
    Public Property CommTemplate As DataTemplate
    Public Property SubCommTemplate As DataTemplate
    Public Overrides Function SelectTemplate(item As Object, container As DependencyObject) As DataTemplate
        Dim node = TryCast(item, TreeViewNode)
        If node IsNot Nothing Then
            If TypeOf node.Content Is CommDaInserire Then
                Return CommTemplate
            End If
            If TypeOf node.Content Is SubComm Then
                Return SubCommTemplate
            End If
        End If
        Return MyBase.SelectTemplate(item, container)
    End Function
End Class

Gif Illustration:


Please find the sample demo in the attachment.

Regards,
Senthilkumar Ranganathan.

Attachment: SfTreeViewVB_c650a317.zip

Loader.
Up arrow icon