WPF窗体的命令绑定

方法一:使用代码

  <WpfUI:View.CommandBindings>
        <CommandBinding Command="Help"
                        CanExecute="HelpCanExecute"
                        Executed="HelpExecuted"
                        />
    </WpfUI:View.CommandBindings>
WPF窗体的命令绑定
 #region Command

        private void HelpCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.baidu.com");
        }

        #endregion Command
WPF窗体的命令绑定

构造函数

WPF窗体的命令绑定
  public TallyBookView()
        {
            InitializeComponent();

            this.InputBindings.Add(
                new KeyBinding(ApplicationCommands.Help, new KeyGesture(Key.F2)));
        }
WPF窗体的命令绑定

上面等同于如下代码:

<WpfUI:View.InputBindings>
        <KeyBinding Command="Help" Key="F2" />
        <KeyBinding Command="NotACommand" Key="F1"/>
    </WpfUI:View.InputBindings>

WPF窗体的命令绑定

上一篇:定要过python二级 第10套


下一篇:[PHP] Http API with JSON data