我正在寫我的第一個WPF應用程序,並試圖讓我的自定義命令工作。自定義命令忽略熱鍵
public static RoutedUICommand Header1 { get; private set; }
.
.
.
gestures = new InputGestureCollection();
gestures.Add(new KeyGesture(Key.D1, ModifierKeys.Control, "Ctrl+1"));
Header1 = new RoutedUICommand("Header 1", "Header1", typeof(EditCommands), gestures);
我再補充一個CommandBindings
節我窗口的XAML。
<!-- local refers to my application's namespace -->
<Window.CommandBindings>
<CommandBinding Command="local:EditCommands.Header1" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"></CommandBinding>
</Window.CommandBindings>
最後,向相關的功能區控件添加了一個命令條目。
<RibbonButton Label="Header 1" Command="local:EditCommands.Header1" SmallImageSource="Images\small.png" ToolTipTitle="Header 1" ToolTipDescription="" ToolTipImageSource="Images\small.png"></RibbonButton>
單擊功能區按鈕可按預期執行處理程序。但是,按Ctrl+1
似乎完全沒有效果。我如何識別我的熱鍵?
Checked NumLock? – AnjumSKhan
@AnjumSKhan:NumLock不應該影響'Key.D1'鍵行爲(在這種情況下有'Key.NumPad1'鍵)。 – Dennis
@AnjumSKhan:我的熱鍵似乎都沒有被識別。 –