Preventing CommandManager WPF from Using CanExecute

Is it possible to prevent WPF CommandManager from executing with CanExecute delegates?

I have an Unhandled Exception Handler procedure that displays an error window for the user. I have a situation when the exception is thrown as part of the CanExecute chain. This calls the exception handler, which displays the window. At this point, the CommandManager launches and requests CanExecute, throwing another exception, calling the handler, showing another window, asking for CanExecute, throwing another exception ... etc. Etc. Etc.

I somehow need to prevent this CanExecute repetition. I tried to simply ignore subsequent errors in the handler, but this means that the exception information in the error window is empty.

+3
source share
1 answer

The best resource is to look at the ICommand interface , which has a CanExecuteChanged Event . Transactions that subscribe to this event will be notified of disconnecting themselves.

It's unclear how your structure is configured, but I would suggest that the triggering operation can fire this event when the process starts, and then when that happens, fire the event again to announce that another processed command can work.

, , , :

private void DoTheCommand()
{
    _isProcessingCabExecute = false;       // Turn off all related for this 
                                           // command (is Execute).

    _opCommand.RaiseCanExecuteChanged();   // Inform all subscribed to check status 
                                           // and disable where possible.

    // The operation

    _isProcessingCabExecute = true;        // All done turn it back on
    _opCommand.RaiseCanExecuteChanged(); // Resume operations.
}
0

Source: https://habr.com/ru/post/1772138/


All Articles