嗨 我在WPF中的CommandBindings有一個奇怪的問題。 我在對象的構造函數中添加CommandBindings。該命令綁定看起來像WPF應用程序命令綁定不起作用
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));
Coresponding功能,這是負責執行一下,這麼一來
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;
}
的問題是,只有削減命令作品。我的意思是,如果我在任何其他funciotn(複製或粘貼)中設置斷點,則不會觸發斷點。有人能告訴我我做錯了什麼嗎?
代碼是否得到了Copy_Enabled方法? – Dabblernl 2010-12-10 10:40:12