![](/img/trans.png)
[英]How do I bind a command to a WPF Telerik radMenuItem in XAML?
[英]WPF Telerik RadMenuItem Not Firing On HotKey
下面的代碼片段來自具有相當實用菜單的生產車間應用程序。...我被要求在某些菜單項中添加熱鍵。 例如,菜單項之一(如下面的代碼所示),我需要將F6鍵添加為熱鍵(請注意單擊vs vs熱鍵的同等命令)...單擊即可正常使用,但是該熱鍵具有似乎沒有任何效果(什么也沒有發生)。
我缺少什么,否則做錯了? 在此先感謝您的幫助。
<telerik:RadMenuItem Name="ToolsMenu" Header="Tools">
<telerik:RadMenuItem Name="ToolsUseFinishLocationMenuItem" Header="Use Finish Location For Bin" Command="{Binding ToolsUseFinishLocationForBinCommand}" InputGestureText="F6">
<telerik:RadMenuItem.InputBindings>
<KeyBinding Key="F6" Command="{Binding ToolsUseFinishLocationForBinCommand}" />
</telerik:RadMenuItem.InputBindings>
</telerik:RadMenuItem>
</telerik:RadMenuItem>
可能是因為您沒有將鍵盤聚焦在元素上。 您可以考慮將輸入綁定到父元素,例如
<Window>
<Window.InputBinding>
<KeyBinding ...>
</Window.InputBinding
<your element/>
</Window>
但是也許問題出在別的地方。 您也可以使用InputManager類為整個應用程序創建熱鍵。
將這些行放入構造函數中:
InputManager.Current.PostNotifyInput -= PostNotifyInputHandler;
InputManager.Current.PostNotifyInput += PostNotifyInputHandler;
並使方法如下:
private void PostNotifyInputHandler(object sender, NotifyInputEventArgs args)
{
var keyboardArgs = args?.StagingItem?.Input as KeyboardEventArgs;
var isSecondEvent = keyboardArgs?.RoutedEvent != Keyboard.PreviewKeyDownEvent;
var performedOnTextBox = keyboardArgs?.OriginalSource is System.Windows.Controls.TextBox;
if (isSecondEvent || performedOnTextBox)
{
return;
}
switch ((keyboardArgs as KeyEventArgs)?.Key)
{
case Key.F6:
// your command here
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.