2
votes

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 assuming that the DatePicker control behaves differently than others as it is still in the Silverlight Toolkit.

2
@user246392-Have you get a chance to look into this : msdn.microsoft.com/en-us/library/cc189015%28VS.95%29.aspxGaurav Arora

2 Answers

1
votes

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

0
votes

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.