How can I determine TreeViewItem clicked in PreviewMouseDown event?
相关问题
- VNC control for WPF application
- Listen for mouse released event on component on wh
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
The following seems to work:
I originally used an extension method on TreeView that takes a UIElement--the sender of the PreviewMouseDown event--like this:
Here's the extension method (it checks the child itself in case you clicked right on a TreeViewItem directly)...
Update:
However, I've since switched it to a more generic version that I can use anywhere.
That either finds the type you're looking for (again, including checking itself) or returns null
You'd use it in the same PreviewMouseDown handler like so...
This came in very handy for when my TreeViewItem had a CheckBox in its template and I wanted to select the item when the user clicked the checkbox which normally swallows the event.
Hope this helps!