2010-12-10 2 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)); 

풀어서 기능이 문제는 명령의 작동을 차단한다는 것입니다 그런 식으로

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 방법에 도착합니까 KeyGestures를 추가 할 필요가? – Dabblernl

답변

0

CopyPaste 명령이 응용 프로그램 창의 모든 컨트롤에 바인딩되어 있습니까? UICut 명령 만 찾고 다른 두 명령은 찾지 않는 것 같습니다. 다른 두 명령을 UI 우물에 묶었는지 확인하십시오.

+0

다른 컨트롤에이 명령을 넣지 마십시오. 나는 단지 수업에서 경계를 만든다. – losieko

0

는 또한

InputBindings.Add(new InputBinding("YourCommand" ,ApplicationCommands.Copy.InputGestures[0])) // Default Gesture is Ctrl+C