Not sure what you mean by TreeNodes.
Typically you would have a corresponding IsSelected
property on your view model that your view binds to:
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Therefore, you would just loop through the data items in your view model and set IsSelected = false
there.
However, it sounds like you don't have such a property. That being the case, you need to get the corresponding TreeViewItem
for each data item. See the TreeView.ItemContainerGenerator
property for info on how to do this. Something like:
var treeViewItem = _treeView.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem;
treeViewItem.IsSelected = false;
HTH,
Kent