Hi Syncfusion team,
I have a STTreeView to map a complex production parts list and I expand the current node and its parents manually. It's made recursive in code but if the current node is in level 4 or lower the ChildNodes collection is not filled anymore. My binded ChildProperty "Substueckliste" is filled and it's shown in the treeview but the ChildNodes are not.
Can you look over it? I've attached screenshots and the code snippets are below:
Codebehind, function to expand the current node:
private void treeView_Loaded(object sender, Syncfusion.XForms.TreeView.TreeViewLoadedEventArgs e)
{
if (treeView.Nodes != null)
{
GetCurrentNode(treeView.Nodes);
}
}
private void GetCurrentNode(TreeViewNodeCollection nodeCollection)
{
foreach (var node in nodeCollection)
{
var content = (StueckListeItem)node.Content;
var childnodes = node.ChildNodes;
if ((childnodes != null && childnodes.Count() > 0) || content.SubStueckliste != null && content.SubStueckliste.Count() > 0)
{
GetCurrentNode(childnodes);
}
if (content.StuecklisteProperties.Gefertigt > 0 && content.StuecklisteProperties.Menge > 0 && content.StuecklisteProperties.Gefertigt >= content.StuecklisteProperties.Menge)
{
content.IstErledigt = true;
node.IsChecked = true;
}
if (content.StuecklisteProperties.BelId == viewModel.BelId)
{
node.IsExpanded = true;
expandParentRecursive(node);
}
}
}
private void expandParentRecursive(TreeViewNode node)
{
if (node != null && node.ParentNode != null)
{
node.ParentNode.IsExpanded = true;
this.expandParentRecursive(node.ParentNode);
}
}
XAML:
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">
<syncfusion:SfTreeView x:Name="treeView"
ItemHeight="40"
Indentation="30"
ExpanderWidth="20"
Loaded="treeView_Loaded"
ChildPropertyName="SubStueckliste"
ItemsSource="{Binding StuecklisteList}"
AutoExpandMode="RootNodesExpanded">
<syncfusion:SfTreeView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Padding="5">
<Image Source="{Binding RessourceImg}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="35" WidthRequest="35"/>
</Grid>
<Grid Grid.Column="1" Padding="5">
<Label Text="" IsVisible="{Binding IstErledigt}" TextColor="#F1700A" FontFamily="fa-solid-900.ttf#Font Awesome 5 Pro Solid" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" FontSize="24"/>
</Grid>
<Grid Grid.Column="2" RowSpacing="1" Padding="-5" >
<Label Text="{Binding Beschreibung}" FontAttributes="{Binding FontAttribute}" FontSize="18"/>
</Grid>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</syncfusion:SfTreeView.ItemTemplate>
</syncfusion:SfTreeView>
</StackLayout>
Thanks in advance :)
Maria
Attachment:
Screenshots_TreeviewChildnodes_861fe0.zip