0

In my user control I have several textboxes e.g. Textbox1, Textbox2.

In the parent I only want to handle KeyDown events raised from Textbox1, not all Textbox

I have added a handler in the parent

this.AddHandler(TextBox.KeyDownEvent, new RoutedEventHandler(OnTextboxGoToPageKeyDown));

but of course this will handle all KeyDown events which I don't want.

Do I have to add some conditional logic in the RoutedEventHandler to check where the event was raised from?

or is there a better way?

What's the best way to do this?

Thanks.

empo
  • 1,133
  • 5
  • 21
  • 41

1 Answers1

0

The RoutedEventArgs in your OnTextboxGoToPageKeyDown has a property named Source which have a references to the Object who raised the event. You can ask for that property when you need to execute your logic.

HTH

Marcote
  • 2,977
  • 1
  • 25
  • 24