WPF:如何使自定义控件上的 KeyBinding 在没有焦点的情况下工作

发布于 2024-11-29 03:38:12 字数 169 浏览 9 评论 0原文

我有两个自定义控件。第一个由文本框和弹出/下拉菜单组成。另一种由扩展器和扩展器内的一些内容组成。

大多数时候,我会在第一个控件的弹出窗口中显示第二个控件。

第二个控件应该有一个用于切换扩展器的热键。

如何在第二个控件中进行键绑定,使其即使焦点位于第一个控件的文本框内也能工作?

I have two custom controls. The first one consists of a textbox and a popup/dropdown. The other consist of a expander and some content inside the expander.

Most of the time, I will display the second control inside the popup of the first.

The second control should have a hotkey for toggling the expander.

How can I make a keybinding in the second control in such a way that it will work even if the focus is inside the textbox of the first control?

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

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

发布评论

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

评论(1

瀞厅☆埖开 2024-12-06 03:38:12

我不认为焦点对于 KeyBindings 的工作始终是必不可少的...您是否尝试将 KeyBinding 的 CommandTarget 设置为您的 Expander 控件?

像下面这样...

<KeyBinding Key="O" Modifiers="Control"
            Command="localns:ApplicationWindow.Open"
            CommandTarget="{x:Static localns:MyWindow.CustomControlInstance.Expander}" />

让我知道这是否有帮助。

I dont think Focus is always essential for KeyBindings to work... did u try setting the CommandTarget of the KeyBinding to your Expander control?

Something like below...

<KeyBinding Key="O" Modifiers="Control"
            Command="localns:ApplicationWindow.Open"
            CommandTarget="{x:Static localns:MyWindow.CustomControlInstance.Expander}" />

Let me know if this helps.

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