2010-07-30 4 views
0

에 박히 :을 발행 WPF 미리보기 처리기에서 명령, 그리고는이 전 다음과 같습니다 XAML이 상상 해보자 루프

<UserControl.CommandBindings> 
    <CommandBinding Command="ApplicationCommands.Delete" Executed="CommandBinding_DeleteExecuted" PreviewExecuted="CommandBinding_PreviewDeleteExecuted"/> 
</UserControl.CommandBindings> 

을 그리고는 다음과 같습니다 C# 코드가 있습니다

private void CommandBinding_DeleteExecuted(object sender, ExecutedRoutedEventArgs e) 
{ 

} 

private void CommandBinding_PreviewDeleteExecuted(object sender, ExecutedRoutedEventArgs e) 
{ 
    //Would like to invoke Delete command from here 
} 

내가하고 싶은 것은 내 미리보기 처리기를 호출하고 사용자 정의 검사를 수행하는 것입니다. 사용자 지정 검사가 통과되면 미리보기 처리기 내에서 delete 명령을 다시 호출하고 싶습니다 (또는 원래의 명령을 '미리보기'를 통과하여 처리기를 실행하면 좋을 것입니다.). . 따라서이 시점에서 delete 명령을 다시 실행하면 더 이상 XAML이 관련되지 않습니다.

미리보기 핸들러에서 삭제 명령을 어떻게 든 다시 실행하면 미리보기 핸들러가 다시 (루프에서 끝없이) 호출되는 결과를 초래할 것이라고 생각합니다. 대신, 다시 발행 된 명령을 내 미리보기 및 처리기를 무시하고 삭제 명령을 처리 트리에서 더 아래로 모든 삭제 명령 처리기 보자 싶습니다.

이렇게 할 방법이 있습니까?

+0

당신이 여기에서 필요로 정확히 확실하지. 따라서 사용자 지정 검사가 통과되면 Executed 처리기를 호출하지 않아도됩니까? 대신에 트리의 다른 명령에서이 명령을 호출하기를 원하십니까? 명령이 전달되지 않으면 호출하려고합니까? –

+0

사용자 지정 검사가 실패한 경우. 그러면 실행 된 핸들러를 호출하지 않아도됩니다. 대신에 아무 일도 일어나지 않습니다. 사용자 지정 검사가 성공하면 내 previewexecute 처리기가없는 것처럼 명령을 호출하려고합니다. – Notre

답변

0

나는 괜찮아 작동하는 것 같군 또 다른 question 기반으로하는 솔루션을 가지고

private void CommandBinding_PreviewDeleteExecuted(object sender, ExecutedRoutedEventArgs e) 
    { 
     bool ignoreDeleteCommand = DoSomeTest(); 


     if (!ignoreDeleteCommand) 
     { 
      foreach (CommandBinding cb in CommandBindings) 
      { 
       if (cb.Command.Equals(ApplicationCommands.Delete)) 
       { 
        //Unsubscribe from this handler, invoke the Delete command (which will be handled by child) and then 
        //resubscribe to this handler 
        cb.PreviewExecuted -= new ExecutedRoutedEventHandler(CommandBinding_PreviewDeleteExecuted); 
        cb.Command.Execute(null); 
        cb.PreviewExecuted += new ExecutedRoutedEventHandler(CommandBinding_PreviewDeleteExecuted); 
       } 
      } 
     } 
    } 
0

명령 처리기는 항상 부모를 먼저 친다. 하나의 명령을 다른 명령으로 프록시하려면 다른 이름을 사용해야합니다.

관련 문제