开发者

Getting KeyInput in Silverlight

Trying to catch keyinput in my Silverlight applicat开发者_开发问答ion 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜