"Can" gaurd without Model

Topics: Conventions
Oct 2, 2011 at 2:45 PM


I started to use Caliburn Micro today - very nice framework. But i ran into a problem:


public class ShellViewModel : Caliburn.Micro.Conductor<Caliburn.Micro.IScreen>.Collection.OneActive
        protected override void OnInitialize()
            DisplayName = "MyApplication 1.0";

        public void ImportData()
            ActivateItem(new DataImportViewModel());            
        public bool CanImportData()
            return this.GetChildren().Where(screen => screen is DataImportViewModel).Count() == 0;

I want to deactivate the menu item in my Shell window if there is already an opened Data Import. The problem is that "CanImportData" is just called at the application startup and never again. 

How can i force that its called?



Oct 2, 2011 at 5:02 PM

Change CanImportData into a property and raise a property change notification anytime you want the guard to update.

Oct 2, 2011 at 5:13 PM

Thanks a lot for the fast reply. How can I set EnforceGuardsDuringInvocation in ActionMessage? Its not a DependecyProperty - so i cant set it in XAML :-S

Oct 2, 2011 at 8:32 PM

It's a configuration option that you set at the application level. Why do you need to set that? 

Oct 3, 2011 at 5:53 AM

As far i understood the meaning of that variable is, that it forces revalidation at every Invoke?

Oct 3, 2011 at 7:50 AM

Yes, that settings ensures that an action is invoked only if the guard is evaluated to true. But you want to control the guard update process, using the property is your best option.