4
的
在我的代碼的的MainView,我有這個事件捉的keyDown:InputBinding代替PreviewKeyDown
#region Constructor
PreviewKeyDown += SoftKeyMainPreviewKeyDown;
#endregion
private void SoftKeyMainPreviewKeyDown(object sender, KeyEventArgs e)
{
var focusedElement = Keyboard.FocusedElement;
switch (e.Key)
{
case Key.Up:
DoSomething();
break;
.....
}
}
現在我想移動到這一點在XAML化InputBindings。
我第一次嘗試:
<UserControl.InputBindings>
<KeyBinding Gesture="Up" Command="{Binding ElementName=_MaschinenView, Path=UpCommand}" />
....
</UserControl.InputBindings>
代碼隱藏:
public ICommand UpCommand { get; set; }
UpCommand = new SimpleCommand { ExecuteDelegate = delegate { MoveFocusInDirection(Keyboard.FocusedElement, new TraversalRequest(FocusNavigationDirection.Up)); } };
有了這個什麼都不會發生。 KeyDown事件很可能是由一個子元素處理的。
是否可以在InputBindings的XAML中設置previewkeydown?如何實現這一目標?