我希望以下行为:
目前我正在处理RoutedEvent,Window.CommandBindings和InputGesture的按键。它工作正常,但我有十个几乎相同的命令(1,2,3 ... 9,0)。还有更好的方法吗?例如,将按下的键发送到CommandBinding.Executed
我的代码示例:
//XAML
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:CustomCommands.SelectOne}" Executed="cmdSelectOne_Executed" />
//CustomCommands.cs
public static class CustomCommands
{
public static RoutedCommand SelectOne = new RoutedCommand();
//...
static CustomCommands()
{
omg.InputGestures.Add(new KeyGesture(Key.D1, ModifierKeys.Control, "Ctrl + 1"));
//...
//MainWindow.xaml.cs
private void cmdSelectOne_Executed(object sender, ExecutedRoutedEventArgs e)