There is a fundamental problem with this design as it stands because users expect clicking the treeview to expand nodes. Now, I appreciate that these are end nodes that you want to click on but, as it stands, the treeview is designed to expand on click.
So, how do you make it behave differently - and do it in a MVVM style, none-hacky, catching events way? Well, the trick is that you are clicking on the text in the header here. Does it have to be text though? Well, no it doesn't - you can change it. But, what do you change it to? Well, visually you want to indicate to the user that clicking on the text has some effect other than expanding a node, and to make things easy for yourself you want something with a
Command
that you can hook your command into. Your first thought might be to use and restyle a button, but this is a bit longwinded. Alternatively, and the one I'd go with, you could use a
Hyperlink
.
So, try this instead:
<TreeViewItem>
<TreeViewItem.Header>
<TextBlock>
<Hyperlink Command="TriggerNotepadCommand">
Notepad
<Hyperlink>
</TextBlock>
</TreeViewItem.Header>
<TreeViewItem>
Then, all you need to do is hook up the command code in your ViewModel.