SketchFlow 中未触发 KeyDown

发布于 2024-09-26 17:41:54 字数 162 浏览 1 评论 0原文

我试图将 KeyDown 事件处理程序添加到 Silverlight SketchFlow 项目中视图的 LayoutRoot,但它似乎没有触发。

如果我将事件类型更改为 MouseLeftButton,该事件就会触发,但我想使用键盘快捷键来演示这一点。

有谁知道如何实现两者?

I'm 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

找个人就嫁了吧 2024-10-03 17:41:54

嗯,由于某些对于不请自来的人来说并不明显的原因,在 XAML 中指定时 KeyDown 事件没有触发。我发现挂钩到代码隐藏中的 Application.Current.RootVisual.KeyDown 就可以解决问题。

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.

波浪屿的海角声 2024-10-03 17:41:54

原因是,当托管在 SketchFlow 播放器中时,您的 LayoutRoot 实际上不是“”布局根。键盘焦点最初位于 Sketchflow 播放器上。

您可以尝试在页面加载事件中添加 Focus() 调用,但也要确保已添加 Jscript 以首先将焦点集中到实际的浏览器 Silverlight 对象。例如

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

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

如果您在托管 Silverlight 应用程序的 HTML/ASPX 页面中没有该代码,则所有按键都会转至浏览器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文