SketchFlow 中未触发 KeyDown
我试图将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,由于某些对于不请自来的人来说并不明显的原因,在 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.原因是,当托管在 SketchFlow 播放器中时,您的 LayoutRoot 实际上不是“”布局根。键盘焦点最初位于 Sketchflow 播放器上。
您可以尝试在页面加载事件中添加 Focus() 调用,但也要确保已添加 Jscript 以首先将焦点集中到实际的浏览器 Silverlight 对象。例如
,
如果您在托管 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.
and
If you don't have that code in the HTML/ASPX page hosting a Silverlight app, all keypresses go the browser instead.