Reputation: 4440
Is there a way to catch a MouseLeftButtonDown (or other mouse event) at a page or user control level and then be able to determine which child control was actually clicked?
Upvotes: 1
Views: 407
Reputation: 24918
Yes. Set up your handler on the page or other UI root, then use the following method to determine what was clicked within that handler.
List<UIElement> hits = System.Windows.Media.VisualTreeHelper.FindElementsInHostCoordinates(args.GetPosition(null), startFromControl);
Note that there are some requirements for controls to be "hit". One common cause is not having a background defined. Controls may also turn hit testing off with the UIElement.IsHitTestVisible property.
Upvotes: 2