You cannot, by why simple reason: there is no such method as
Selected
in the class
System.Windows.Controls.TreeViewItem
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem%28v=vs.110%29.aspx[
^].
Moreover, such method could not appear in the code of anyone knowing English and understanding reasonable naming conventions. There is an event with this name though. The whole problem is unclear. Selection is the property of the
TreeView
, not your control.
Normally, any tree node can be selected. Making some nodes unselectable can be a pretty difficult work. You would rather need to create a derived class of the tree view. You would need to handle a number of events which would detect an attempt to select some node, determine if it can be selected or not, and if it is not, some nearby node should be selected instead. Say, if you select nodes by up and down arrow keys, selection should "jump" over the unselectable node. If you are moving up, and the node on top is unselectable one, you would need to cancel the event and its further propagation, same thing about moving down. Something like that should happen on the click on the unselectable node itself. This would be a good deal of research and development. Nothing impossible though. :-)
—SA