如何从用户控件创建页面/窗口的输入手势
我有一个可重用的用户控件,它使用一些命令和相应的键盘手势, (特别是 Escape 和 Ctrl+1...Ctrl+9)
现在,当我在多个位置使用此用户控件时,我想在用户控件中定义输入手势,只要焦点位于用户控件内,它就可以正常工作。 但是,只要焦点位于当前页面/窗口内,我就需要它工作。
我该怎么做,或者我真的必须在每个页面上进行命令/输入绑定吗?
I have a reusable usercontrol that uses a few commands and corresponding keyboard gestures,
(specifically Escape and Ctrl+1...Ctrl+9)
Now as I use this usercontrol in multiple locations I'd like to define the input gestures in the usercontrol, which works fine as long as the focus is within the usercontrol. However, I'd need it to work as long as focus is within the current page/window.
How can I do it, or do I really have to do command/input bindings on every page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以处理
UserControl
的Loaded
事件,并沿着逻辑树向上查找所属页面/窗口,然后您可以在其中添加绑定。例如
You could handle the
Loaded
event of theUserControl
and walk up the logical tree to find the owning page/window, then you can add the bindings there.e.g.