开发者

Hotkeys in Silverlight?

Is there a way to create global keys in Silverlight? I added a KeyDown event handler to the topmost Page element. I can catch the key signal when elements like a Button, TextBox, Calendar, and RichTextBox have focus. But the DatePicker won't let me handle the key down event at the Page level. Any way to make a hotkey in non-OOB SL?

P.S. I am assumin开发者_JS百科g that the DatePicker control behaves differently than others as it is still in the Silverlight Toolkit.


have you tried using the AddHandler method? With this method you can add a handler and define if you want to handle already handled events, too.

In my simple example I added it to the RootVisual in the app.xaml.cs.

private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();
            RootVisual.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(HandleKeyDown), true);
        }

        private void HandleKeyDown(object sender, KeyEventArgs e)
        {
            //Add your keyhandling code here
            Debug.WriteLine(e.Key);
        }

I tried it with a DatePicker and it works.

Hope this helps!

BR,

TJ


This may help you. The author provides two ways using HTML bridge (when your Silverlight does not have focus) and using the KeyUp event on Application.RootVisual.

I have not tried it myself so I wouldn't know if it's working.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜