【发布时间】:2010-03-27 18:43:52
【问题描述】:
我使用标准的剪切、复制和粘贴命令(这是 ApplicationCommands 类的一部分)。是否可以重新定义 CanExecute 方法?
这是我的代码:
XAML:
<Window.CommandBindings>
<CommandBinding Command="Copy"
CanExecute="CopyCanExecute" Executed="CopyExecuted"/>
</Window.CommandBindings>
<StackPanel>
<TextBox Name="txt"></TextBox>
<Button Command="Copy" CommandTarget="{Binding ElementName=txt}">copy</Button>
</StackPanel>
代码隐藏:
private void CopyCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
}
private void CopyExecuted(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Copy Executed");
}
按钮的行为仍然像它的命令是标准的复制命令。
【问题讨论】: