WPF窗体的命令绑定

时间:2014-02-09 17:52:09   收藏:0   阅读:568

方法一:使用代码

  <WpfUI:View.CommandBindings>
        <CommandBinding Command="Help"
                        CanExecute="HelpCanExecute"
                        Executed="HelpExecuted"
                        />
    </WpfUI:View.CommandBindings>
bubuko.com,布布扣
 #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
bubuko.com,布布扣

构造函数

bubuko.com,布布扣
  public TallyBookView()
        {
            InitializeComponent();

            this.InputBindings.Add(
                new KeyBinding(ApplicationCommands.Help, new KeyGesture(Key.F2)));
        }
bubuko.com,布布扣

上面等同于如下代码:

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

原文:http://www.cnblogs.com/quietwalk/p/3541658.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!