开发者

Getting KeyInput in Silverlight

开发者 https://www.devze.com 2023-02-06 20:23 出处:网络
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

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

精彩评论

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

关注公众号