嗨,我对 WPF 中的 CommandBindings 有一个奇怪的问题。我在对象的构造函数中添加了 CommandBindings。命令绑定看起来像这样
CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy,Copy_Executed,Copy_Enabled));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut,Cut_Executed,Cut_Enabled));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste,Paste_Executed,Paste_Enabled));
负责执行的对应函数看起来是这样的
private void Paste_Enabled(object sender,CanExecuteRoutedEventArgs e)
{
e.CanExecute = selectionService != null && selectionService.CurrentSelection.Count > 0;
}
private void Paste_Executed(object sender, ExecutedRoutedEventArgs e)
{
if (GetSelected() != null)
Paste(true);
else
Paste(false);
}
private void Copy_Executed(object sender, ExecutedRoutedEventArgs e)
{
Copy();
}
private void Copy_Enabled(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = selectionService.CurrentSelection.OfType<DesignerItem>().Count() > 0;
}
#endregion
private void Cut_Executed(object sender, ExecutedRoutedEventArgs e)
{
Copy();
DeleteCurrentSelection(false);
}
private void Cut_Enabled(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = this.SelectionService.CurrentSelection.Count() > 0;
}
问题是只有 cut 命令有效。我的意思是,如果我在任何其他功能(复制或粘贴)中设置断点,则不会命中断点。有人可以告诉我我做错了什么吗?