2010-12-10 24 views
1

こんにちは 私は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(コピーまたは貼り付け)でブレークポイントを設定すると、ブレークポイントにヒットしないことを意味します。誰かが私が何をやっているのか教えてもらえますか?

+0

コードがCopy_Enabled方法を取得していますか? – Dabblernl

答えて

0

CopyPasteコマンドは、アプリケーションウィンドウのどのコントロールにもバインドされていますか? UICutコマンドだけを検索し、他の2つのコマンドは検索しないように見えます。他の2つのコマンドをUIに縛っていることを確認してください。

+0

私はこのコマンドを他のコントロールに割り当てないでください。私はちょうどクラスで境界を作る – losieko

0

あなたはKeyGesturesを追加する必要も

InputBindings.Add(new InputBinding("YourCommand" ,ApplicationCommands.Copy.InputGestures[0])) // Default Gesture is Ctrl+C 
関連する問題