views:

325

answers:

1

Hello,

I've a UserControl which contains a TextBox called myTextBox. This UserControl is placed in a MainWindow.xaml where I'm trying to catch the "UIElement.PreviewKeyUp".

Now when debugging, I can see the "UserControl" as sender, not the TextBox. How can I check if the KeyEventArgs e (especially e.Key) were sent from the TextBox called myTextBox?

Thanks for any help.

Cheers

A: 

You can find it as the e.Source property. Try to cast it to 'TextBox', and if it succeeds, you can check the Name property for 'myTextBox'.

[edited after comment]

If the TextBox is inside a UserControl, you can use the OriginalSource property of the event.

Eric Minkes
Thanks Eric. Unfortunately this doesn't work.. the debugger shows me in the e.Source the UserControl. Please have a look at this screenshot: http://img22.imageshack.us/img22/7873/scrntextboxevent.png
Joseph Melettukunnel
Ah, worked like a charm!
Joseph Melettukunnel