wpf----命令(Command)

Posted frogkiller

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpf----命令(Command)相关的知识,希望对你有一定的参考价值。

一,自定义命令:

1创建一个类的静态RoutedUICommand对象.并且在类初始化中创建该静态对象. 本实列创建了该类和类中的静态对象.

 public class DataCommands
    {
        private static RoutedUICommand requery;
        static DataCommands()
        {
            InputGestureCollection inputs = new InputGestureCollection();
            inputs.Add(new KeyGesture(Key.R, ModifierKeys.Control, "Ctrl+R"));
            requery = new RoutedUICommand(
              "Requery", "Requery", typeof(DataCommands), inputs);
        }

        public static RoutedUICommand Requery
        {
            get { return requery; }
        }
    }

(注意,是类的一个静态属性).


2,使用该命令:

以上是关于wpf----命令(Command)的主要内容,如果未能解决你的问题,请参考以下文章