D. Veloper
D. Veloper

Reputation: 1517

Getting KeyInput in Silverlight

Trying to catch keyinput in my Silverlight application gives me problems because of the focus of the controls. The page consists of multiple controls so every time a diffent control has focus and so my KeyDownEvent usually fails. One possibility is to assing a KeyDown event to ALL my controls and then to the method that processes them. Is there a better way?

Upvotes: 1

Views: 36

Answers (1)

Almund
Almund

Reputation: 6226

You could catch the KeyDown in the page that contains all controls by overriding OnKeyDown.

protected override void OnKeyDown(KeyEventArgs e)
{
  // Distribute to listeners from here
}

This works since the controls on the page bubbles the event upwards so that if the control (like textbox/button etc) doesn't handle the keypress the parent control gets a chance.

Upvotes: 1

Related Questions