Caliburn Micro - is it possible to intercept calls to execute a command?
I want to add error handling to my view-models so that when a command is executed and an exception thrown, the error is handled gracefully and a modal dialog displayed.
I've got this working but my approach is a too wordy. Errors are trapped within a command and then published via an IObservable. A behavior subscribes to the errors - creating an appropriate view model and passing to the WindowManager. While it works, I'd prefer something more declarative.
Instead I want to decorate or intercept calls to commannds (bound to a button) and provide generic error handling. The try-catch might call out to a method on the view model or command that is decorated with a Rescue attribute.
I unders开发者_运维百科tand this is possible within Caliburn but can it be done with Micro? Perhaps there's an alternative approach?
Have a look at this question I asked on SO and subsequently answered with help via the CM codeplex forum.
I slightly modified the RescueAttribute
of this CM filters implementation to allow the error handling routine to be executed as a coroutine.
This in combination with the ShowModal
IResult
available in some of the samples should get you what you want.
精彩评论