<Syncfusion:SfTreeView Grid.Row="1" HorizontalAlignment="Left" Width="369" Margin="4,2,0,2"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ShowLines="True" ShowRootLines="True" UseLayoutRounding="False"
ItemsSource="{Binding SelectedRepository.Nodes}"
ChildPropertyName="ChildNodes"
LoadOnDemandCommand="{Binding ReadChildNodesCommand}"
SelectionMode="Single"
SelectedItem="{Binding SelectedNode}">
<Syncfusion:SfTreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</Syncfusion:SfTreeView.ItemTemplate>
</Syncfusion:SfTreeView>
The SelectedNode is in ViewModel defined as follows:
private object? selectedNode = null;
public object? SelectedNode { get => selectedNode; set => Set(nameof(SelectedNode), ref selectedNode, value); }
The SfTreeView is showing all data, I can select any item, but the value of SelectedNode is not changing. What am I doing wrong?
My second question is related to refreshing data: If I got it well, SelectedItem points to the data binded with the node. This node has also childnodes. If I refresh the data, how should I populate the items?
Cheers.
|
Queries |
Solutions | |
|
The SfTreeView is showing all data, I can select any item, but the value of SelectedNode is not changing. What am I doing wrong?
|
Your requirement can be achieved by enabling the UpdateSourceTrigger property as PropertyChanged and set Mode as TwoWay for SelectedItem property in SfTreeView. Please refer the below code snippet,
Sample Link: https://www.syncfusion.com/downloads/support/forum/171805/ze/LoadOnDemand41424265 For more information related to Selection, please refer the below user guide documentation link, UG Link: https://help.syncfusion.com/wpf/treeview/selection | |
|
My second question is related to refreshing data: If I got it well, SelectedItem points to the data binded with the node. This node has also childnodes. If I refresh the data, how should I populate the items?
|
You can load child items for the node in Execute method of LoadOnDemandCommand. Execute method will get called when user expands the tree node. For more information related to On-demand loading of child items, please refer the below user guide documentation link,
|