Change the selected item of a treeview in WPF

自古美人都是妖i 提交于 2019-12-24 17:15:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!