【发布时间】:2015-08-02 21:07:36
【问题描述】:
我正在尝试将 KeyBinding 的键属性绑定到这样的键属性:
<i:Interaction.Triggers>
<local:InputBindingTrigger>
<local:InputBindingTrigger.InputBinding>
<KeyBinding Key="{Binding SettingsViewModel.PreviousHotkey}"/>
</local:InputBindingTrigger.InputBinding>
<cal:ActionMessage MethodName="FormKeyDown"/>
</local:InputBindingTrigger>
</i:Interaction.Triggers>
PreviousHotkey 是 Key 类型的属性。
public Key PreviousHotkey
{
get { return _previousHotkey; }
set { _previousHotkey = value; }
}
据我了解,KeyBindings 是应用程序范围内的,所以哪个控件有焦点并不重要吗? 当我执行时,输出中出现以下错误:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=SettingsViewModel.PreviousHotkey; DataItem=null; target element is 'KeyBinding' (HashCode=24311996); target property is 'Key' (type 'Key')
它似乎也不起作用。
如何绑定 KeyBinding 的 Key 属性?
【问题讨论】:
标签: c# wpf key-bindings