2010-01-25 62 views

回答

1
<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; 
} 
+0

没有cs请。通过XAML实现 – jawahar 2010-01-25 05:56:38

+1

Iam不太确定它是否只能通过XAML完成。无论如何,还有一个建议是这样的。 <![CDATA [ 空隙ButtonClickMethod(对象发件人,EventArgs的) { btn1.Background = Brushes.Green!; MessageBox.Show(“Red Button clicked”); } ]]> 2010-01-25 06:17:46

1

执行和CanExecute是接口的ICommand的成员,因此你不能只在XAML中使用它。只能在xaml中使用的唯一命令是系统执行的命令,例如复制,剪切和粘贴,可用于文本框(例如)。您必须为ICommand的实现提供支持,您可以绑定到来自视图模型的命令,但必须有代码。