zoukankan      html  css  js  c++  java
  • Shortcut key for WPF

    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");
            }
  • 相关阅读:
    努力 加油
    大总结(全文手打)加深记忆 表单 注册页面的第一次制作 小白一只多多包含
    购物栏
    三级轮播
    图片轮播
    啊!!苦等,博客终于通过了!!
    SQL升级Oracle挖的Null坑,你懂的!
    关于master..xp_cmdshell’的几个错误_解决办法(转)
    班级博客
    图片系统架构思考之一:删除图片--不容忽视
  • 原文地址:https://www.cnblogs.com/skyfei/p/2009047.html
Copyright © 2011-2022 走看看