问题
I have a treeview with several items in it. How do I force the treeView to select a specific item ? Everytime I try to use any of the "Selected..." property, I get the error that it is read-only and cannot be set either in code or in XAML.
Regards,
回答1:
You need to create a Selected
property on your tree item's ViewModel, and bind to it.
Here is an article that explains how to do it.
Edit. Actually that uses a different way. The article I was thinking of was this one
来源:https://stackoverflow.com/questions/9177946/change-the-selected-item-of-a-treeview-in-wpf