Not sure what you mean by TreeNodes.
Usually you have the corresponding IsSelected property on your view model that your view is associated with:
<TreeView> <TreeView.ItemContainerStyle> <Style TargetType="TreeViewItem"> <Setter Property="IsSelected" Value="{Binding IsSelected}"/> </Style> </TreeView.ItemContainerStyle> </TreeView>
Therefore, you simply scroll through the data elements in your view model and set IsSelected = false .
However, it seems that you do not have such a property. In this case, you need to get the corresponding TreeViewItem for each data item. For information on how to do this, see the TreeView.ItemContainerGenerator Property. Something like:
var treeViewItem = _treeView.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem; treeViewItem.IsSelected = false;
Kent boogaart
source share