WPF自定义快捷命令

1、创建一个类

public class CustomCommandTest
{
    private static RoutedUICommand customCommand;

    public static RoutedUICommand CustomCommand
    {
        get { return customCommand; }
    }

    static CustomCommandTest()
    {
        InputGestureCollection inputGestureCollection = new InputGestureCollection();
        inputGestureCollection.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R"));
        customCommand = new RoutedUICommand("", "CustomCommand", typeof(CustomCommandTest), inputGestureCollection);
    }
}

2、在xaml中使用该类

<Window.CommandBindings>
    <CommandBinding Command="{x:Static local:CustomCommandTest.CustomCommand}" Executed="CustomCommand_Execute"/>
</Window.CommandBindings>

        -- 其中的Executed就是摁下快捷键要调用code_behind的方法

相关推荐

  1. WPF定义快捷命令

    2024-03-11 03:16:08       48 阅读
  2. 定义 Linux 快捷命令

    2024-03-11 03:16:08       39 阅读
  3. Wpf-定义图标Button

    2024-03-11 03:16:08       38 阅读
  4. WPF定义模板--Lable

    2024-03-11 03:16:08       33 阅读
  5. WPF定义模板--ToggleButton

    2024-03-11 03:16:08       26 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-11 03:16:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-11 03:16:08       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-11 03:16:08       82 阅读
  4. Python语言-面向对象

    2024-03-11 03:16:08       91 阅读

热门阅读

  1. web蓝桥杯真题:冰墩墩心情刻度尺

    2024-03-11 03:16:08       52 阅读
  2. 【c++】模板的使用

    2024-03-11 03:16:08       47 阅读
  3. 设计模式 | 单例模式 | 懒汉&饿汉

    2024-03-11 03:16:08       43 阅读
  4. python的类修饰器

    2024-03-11 03:16:08       50 阅读
  5. LeetCode1547. Minimum Cost to Cut a Stick——区间dp

    2024-03-11 03:16:08       51 阅读
  6. 前端缓存使用规范

    2024-03-11 03:16:08       34 阅读
  7. 深入了解 Jetpack Compose 中的 Modifier

    2024-03-11 03:16:08       47 阅读