永远的SKYFEI
喜欢在阳光下,光着脊梁,挥汗如雨地工作,每次回头擦汗,看到的都是成就!

steps:

open the window code page, and find the construction function;

add code like below:

 

 public MainWindow()
        {
            InitializeComponent();

            
// Create the CommandBinding.
            CommandBinding cmd = new CommandBinding();
            cmd.Command 
= ApplicationCommands.New;

            cmd.Executed 
+= new ExecutedRoutedEventHandler(CommandBinding_CmdKey_Executed);
            cmd.CanExecute 
+= new CanExecuteRoutedEventHandler(CommandBinding_CmdKey_CanExecute);
            
this.CommandBindings.Add(cmd);
            
// Creating a KeyBinding between the Open command and Ctrl-R
            KeyBinding CmdKey = new KeyBinding();
            CmdKey.Key 
= Key.F;
            CmdKey.Modifiers 
= ModifierKeys.Control;
            CmdKey.Command 
= cmd.Command;
            
this.InputBindings.Add(CmdKey);
        }
        
private void CommandBinding_CmdKey_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute 
= true;
        }

        
private void CommandBinding_CmdKey_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show(
"OK");
        }

 

posted on 2011-04-08 10:07  skyfei  阅读(504)  评论(0编辑  收藏  举报