禁用WPF TreeView(或TreeViewItem)选择?

问题描述:

是否有一种好方法(除了重新模版整个TreeViewItem.Template之外)来禁用TreeView中的选择?

Is there a nice way (except retemplating the whole TreeViewItem.Template) to disable selection in TreeView?

我基本上是在寻找TreeViewItemsControl样式(ItemsControl是在ListBox上禁用"选择的最佳用途,请阅读帖子)

I am basically looking for the ItemsControl style of the TreeView (An ItemsControl is the best use to 'disable' selection on ListBox, read this post)

每当项被选择,则可以 取消选择" 它.前任.从 http://www.codeproject.com/KB/WPF/TreeView_SelectionWPF.aspx修改代码或使用MVVM方法(请参见 http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx ),并始终将IsSelected设置回false.

Whenever an item is selected, you could "unselect" it. Ex. modify the code from http://www.codeproject.com/KB/WPF/TreeView_SelectionWPF.aspx or use a MVVM approach (see http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx) and always set IsSelected back to false.