c# - WPF pass pressed key to command handler -


i desire following behavior:

  • pressing ctrl + 1 causes selecting first item list
  • ctrl + 2 selects first 2 elements
  • and on.

currently i'm handling pressed keys routedevent, window.commandbindings , inputgesture. works fine, have ten same commands (1,2,3...9,0). there better way? eg, sending pressed key commandbinding.executed

sample of code:

//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) 


Comments