WPF TreeView PreviewMouseDown on TreeViewItem

Posted by imekon on Stack Overflow See other posts from Stack Overflow or by imekon
Published on 2010-06-01T12:57:35Z Indexed on 2010/06/01 13:03 UTC
Read the original article Hit count: 293

Filed under:
|
|
|

If I handle the PreviewMouseDown event on TreeViewItem, I get events for everything I click on that TreeViewItem include the little +/- box to the left (Windows XP). How can I distinguish that?

I tried the following:

// We've had a single click on a tree view item
// Unfortunately this is the WHOLE tree item, including the +/-
// symbol to the left. The tree doesn't do a selection, so we
// have to filter this out...
MouseDevice device = e.Device as MouseDevice;

// This is bad. The whole point of WPF is for the code
// not to know what the UI has - yet here we are testing for
// it as a workaround. Sigh...

// This is broken - if you click on the +/- on a item, it shouldn't
// go on to be processed by OnTreeSingleClick... ho hum!
if (device.DirectlyOver.GetType() != typeof(Path))
{
    OnTreeSingleClick(sender);
}

What I'm after is just single click on the tree view item excluding the extra bits it seems to include.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about treeview