Thursday, 15 May 2014

C#/WPF: Catch Routed Event (UIElement.PreviewKeyUp) from UserControl -


I have a UserControl that has a text box named MyTextBox. This UserControl is placed in MainWindow.xaml, where I have the "UIElement .PreviewKeyUp "is trying to catch up.

Now while debugging, I can see the "UserControl" as the sender, not the text box.

Cheers

Cheers

How can I check whether KeyEventArgs E (especially EK) was sent from the text box whose Is myTextBox the name?

You can find it as e.Source property. Try putting it on the 'text box', and if it succeeds, you can check the name property for 'myTextBox'.

[edit after comment]

If the text box is inside UserControl, you can use the OriginalSource property of the event.


No comments:

Post a Comment