Guard Method Re-evaluation

Sep 24, 2010 at 6:14 PM


Is it possible for a ViewModel to force all of its Guard methods to be re-evaluated? If so, how?

Basically, I have two ViewModel models. ViewModel "A" broadcasts an event via the EventAggregator. ViewModel "B" listens for this event. When B  receives the event it needs to some way to tell the View that things have changed and that it needs to enable some of the controls it contains. This raises a secondary question, is there a better way of doing this? Rather than relying on inter ViewModel communication and some other jiggery-pokery?

Third question, what causes CM to trigger guard clause re-evaluation during the normal course of events?


Barry Carr

Sep 24, 2010 at 6:40 PM

If you have property guards, you can just raise a change notification with a null property name. That will trigger all guards to be re-evaluated. I think we also have a Refresh() method on the PropertyChangedBase that does this for you. If you are using methods for guards, those can only be re-evaluated when their parameters (if they have any) change. If you need something more custom, I would take a look at this recipe.

Sep 24, 2010 at 7:48 PM

Thanks, Rob. I got a bit blinkered there, I didn't realise that Guards could be properties, I thought they had to be methods. Changing my Guards to properties sorted me out.