WPF中的箭头键绑定问题 [英] Arrow Key Binding Problem in WPF
本文介绍了WPF中的箭头键绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有关于箭头键绑定到命令的问题。其他键工作正常。例如,下面的xaml代码,工作正常
Hi people,
I have a problem about arrow key binding to command. Other keys works fine. For example, the xaml code in below, works fine
<Window.InputBindings>
<KeyBinding Command="{Binding Path=DenemeCommand}" Key="A" />
</Window.InputBindings>
但是遵循xaml代码doest not
But following xaml code doest not
<Window.InputBindings>
<KeyBinding Command="{Binding Path=DenemeCommand}" Key="Left" />
</Window.InputBindings>
有在代码隐藏中是相同的stuation。
下面的代码工作正常
There is same stuation in codebehind.
Code in below works fine
var viewmodel = (ViewModels.ViewModelLocator)FindResource("Locator");
var gesture = new KeyGesture(Key.Delete);
var inputBinding = new InputBinding(viewmodel.MainViewModel.DenemeCommand, gesture);
InputBindings.Add(inputBinding);
此代码没有。
this code does not.
var viewmodel = (ViewModels.ViewModelLocator)FindResource("Locator");
var gesture = new KeyGesture(Key.Left);
var inputBinding = new InputBinding(viewmodel.MainViewModel.DenemeCommand, gesture);
InputBindings.Add(inputBinding);
我不明白为什么会这样。不仅是左键。所有箭头键(右,下等)都不会触发命令执行。
提前谢谢。
I can not understand why this happen. Not only left key. All arrow key(Right,Down etc.) does not trigger the command execution.
Thanks in advance.
推荐答案
我有同样的问题,你找到了解决办法吗?
Hi,
I have the same problem, did you find any solution?
这篇关于WPF中的箭头键绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文