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
<syncfusion:SfTreeView Name="SFTW_Comm" ItemsSource="{Binding ListaCommDaInserire}" ChildPropertyName="ListaSubComm" ItemTemplateSelector="{StaticResource CommTreeTemplateSelector}"/> |
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 |
Attachment: SfTreeViewVB_c650a317.zip
- 1 Reply
- 2 Participants
-
MD marco del frate
- Feb 27, 2026 07:28 AM UTC
- Mar 2, 2026 01:58 PM UTC