开发者

KeyDown not fired in SketchFlow

I'开发者_如何学Cm trying to add a KeyDown event handler to the LayoutRoot of a view in a Silverlight SketchFlow project, but it doesn't seem to fire.

The event fires if I change the event type to MouseLeftButton, but I want to demonstrate this using a keyboard-shortcut.

Does anyone know how to accomplish both?


Well, for some reasons not obvious to the uninvited, the KeyDown event did not fire when specified in XAML. I found that hooking onto the the Application.Current.RootVisual.KeyDown in code-behind does the trick.


The reason is that your LayoutRoot is actually not "the" layout root when hosted in a SketchFlow player. Keyboard focus is initially on the Sketchflow player.

You might try adding a Focus() call in your page loaded event, but also make sure you have added the Jscript to initially focus to the actual browser Silverlight object first. e.g.

<script type="text/javascript">
        function appLoad(sender, args) {
            var xamlObject = document.getElementById('SilverlightObject');
            if (xamlObject != null)
                xamlObject.focus();
        }

and

<object id='SilverlightObject' data= ...
            [snip]
            <param name="onError" value="onSilverlightError" />
            <param name="onLoad" value="appLoad" />

If you don't have that code in the HTML/ASPX page hosting a Silverlight app, all keypresses go the browser instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜