1

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

4

2 に答える 2

0

KeyGesturesも追加する必要があります

  InputBindings.Add(new InputBinding("YourCommand" ,ApplicationCommands.Copy.InputGestures[0])) // Default Gesture is Ctrl+C 
于 2010-12-10T10:36:30.780 に答える
0

Copyおよびコマンドは、アプリケーション ウィンドウのいずれかPasteのコントロールにバインドされていますか? UIコマンドのみを検索し、Cut他の2つのコマンドを検索しないように見えます。他の 2 つのコマンドをUIウェルにバインドしたことを確認してください。

于 2010-12-10T10:20:52.143 に答える