How to intercept execution of a RoutedCommand within the view? (WPF / MVVM)

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 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?

Thanks,

Tim


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;
链接地址: http://www.djcxy.com/p/1644.html

上一篇: 不确定组织

下一篇: 如何拦截视图中的RoutedCommand的执行? (WPF / MVVM)