Wpf 通过xaml命令绑定
如何通过XAML调用execute和Canexecute方法?execute和Canexecute是接口ICommand的成员,因此不能仅在XAML中使用它。您只能在xaml中使用的命令是系统实现的命令,例如,可以在文本框上使用的复制、剪切和粘贴命令。ICommand的实现必须有支持,您可以从视图模型绑定到命令,但必须有代码。请不要使用cs。通过XAML实现我不太确定是否只能通过XAML实现。无论如何,还有一个建议。Wpf 通过xaml命令绑定,wpf,Wpf,如何通过XAML调用execute和Canexecute方法?execute和Canexecute是接口ICommand的成员,因此不能仅在XAML中使用它。您只能在xaml中使用的命令是系统实现的命令,例如,可以在文本框上使用的复制、剪切和粘贴命令。ICommand的实现必须有支持,您可以从视图模型绑定到命令,但必须有代码。请不要使用cs。通过XAML实现我不太确定是否只能通过XAML实现。无论如何,还有一个建议。 <Window.CommandBindings> <
<Window.CommandBindings>
<CommandBinding Command="Help" CanExecute="HelpCanExecute" Executed="HelpExecuted" />
</Window.CommandBindings>
<Button Command="Help" Content="Help Command Button" />
private void HelpCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
e.Handled = true;
}
private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Hey, I'm some help.");
e.Handled = true;
}