您的位置:首页 > 其它

WPF窗体的命令绑定

2014-02-09 16:34 183 查看
方法一:使用代码

<WpfUI:View.CommandBindings>
<CommandBinding Command="Help"
CanExecute="HelpCanExecute"
Executed="HelpExecuted"
/>
</WpfUI:View.CommandBindings>


#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


构造函数

public TallyBookView()
{
InitializeComponent();

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


上面等同于如下代码:

<WpfUI:View.InputBindings>
<KeyBinding Command="Help" Key="F2" />
<KeyBinding Command="NotACommand" Key="F1"/>
</WpfUI:View.InputBindings>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: