I have a UserControl WPF that contains a button. I also have a WPF window containing a button. In UserControl and Window, I put the following line in XAML:
UIElement.PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown"
and in 'OnPreviewMouseLeftButtonDown' I put a debug print that displays args.Source.
When I click the button inside the window, I get the button as the EventArgs source. However, when I click on the button that is inside the UserControl (which is also inside the window, so I can test it, but not in the same window), I get the UserControl as the source of EventArgs.
I'm tired of seeing if there is any decorator around UserControl (using snoop), but that seems straightforward.
I canβt understand what is especially important in UserControl in WPF that I donβt get the right sender. Can someone explain to me what I am missing?
source share