WPF TextBox Intercepting RoutedUICommands

前端 未结 6 1333
自闭症患者
自闭症患者 2021-02-14 03:10

I am trying to get Undo/Redo keyboard shortcuts working in my WPF application (I have my own custom functionality implemented using the Command Pattern). It seems, however, tha

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 03:34

    The Executed event bubbles up, so the Window Executed event will always be hit after the TextBox Executed event. Try changing it to PreviewExecuted and it should make a huge difference. Also, you might need to hook up a CanExecute for your window as well. ie:

    
    
    private void SomeOtherFunction(object sender, ExecutedRoutedEventArgs e) { e.CanExecute=true; }
    

    Of course you'll probably want some logic in there to determine when CanExecute should be set to true. You probably don't need to use a custom command either (just use the built-in Undo).

提交回复
热议问题