【发布时间】:2017-11-02 07:51:15
【问题描述】:
我想将我的Button 的Keybindings 绑定到我的Window 的Keybindings。
我的窗口 (Name="Mainwindow) 输入绑定:
<Window.InputBindings>
<KeyBinding Key="Return" Command="{Binding KeyPressed}" CommandParameter="Next"/>
</Window.InputBindings>
我对按钮应该是什么样子的想法
<Button Content="Select Directory" Command="{Binding BrowseDirectory}">
<Button.InputBindings>
<KeyBinding Key="Return" Command="{Binding ElementName=Mainwindow, Path=InputBindings}"/>
</Button.InputBindings>
</Button>
遗憾的是,Outwindow 没有显示任何类型的 Binderror 任何其他内容,以便让我了解它为什么不起作用。
所以基本上问题是:如何将Control.InputBindings 绑定到另一个Control.InputBindings?
【问题讨论】:
-
如果你在窗口上有键绑定,那么当按下正确的键时就会触发命令,在按钮上复制它会浪费时间
-
当按钮获得焦点时,返回按钮将触发 button.clicked 事件 --> 它将开始执行命令。我正在寻找一种方法来克服这个问题,现在我决定将
中的内容复制粘贴到 。不漂亮,但在我找到时间寻找合适的解决方案之前完成了这项工作。
标签: c# wpf binding inputbinding