我将我的文本框绑定到ViewModel类。但是,按钮命令(这是一个RelayCommand,从ICommand扩展)我绑定到UsersView.xaml.cs。 UsersView.xaml.cs构造函数我有这个:KeyBinding - RelayCommand在xaml.cs中
DataContext = UserVM;
btnAdd.DataContext = this;
这是我如何绑定按钮 - 它的工作原理。
<Button Command="{Binding Add}" Content="Add user" />
现在,我想补充KeyGesture该按钮,但我不能化InputBindings设置的DataContext和编译器无法找到这UsersVM类添加命令。
<UsersView.InputBindings>
<KeyBinding Key="F10" Command="{Binding Add}" />
</UsersView.InputBindings>
你试过了吗?Command =“{Binding Path = DataContext.Add}”'?这是在黑暗中拍摄的,但它可能奏效。 – sellmeadog
不工作。谢谢。 – davor