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");
            }
  • 相关阅读:
    常用正则表达式实例
    java doc注释
    不让WINDOWS检测硬盘的方法
    maven eclipse插件使用问题解决
    indexof 和 indexofany有什么区别
    asp.net验证码
    C#里如何把数据库里的日期显示为只包含年月日
    雷人的发现 谷歌浏览器三大不为人知的秘密
    三层架构实例
    正则表达式30分钟入门教程
  • 原文地址:https://www.cnblogs.com/skyfei/p/2009047.html
Copyright © 2011-2022 走看看