How to intercept execution of a RoutedCommand within the view?
In a WPF / MVVM application, I am trying to find a code-efficient way to set the main view cursor to Cursors.Wait
prior to any lengthy operation and to restore it to the default cursor after completion.
Since all operations are invoked using routed开发者_JAVA百科 commands, I'd like to find a way of intercepting command execution, ideally by creating a generic command class that wraps an instance of a built-in routed command, but I can't visualize how to do this.
Specifically, the RoutedCommand.Execute
method is not virtual so I need another mechanism to intercept its calls. Also, I am not sure how an instance of the generic command class would reference the view for which it has to set the cursor.
Any advice please?
You can set the Cursor in a static manner. The effect is that the cursor will be 'Wait' while the app has focus rather than when it is over a certain control.
The code, which would be part of the ViewModel at the start of the lengthy operation:
Mouse.OverrideCursor = Cursors.Wait;
After the operation is complete you have to clear the override like this:
Move.OverrideCursor = null;
精彩评论