Search code examples
mvvmdatatemplatecaliburn.micro

Disabling Caliburn.Micro View/ViewModel binding convention for a given V/VM pair


I love Caliburn Micro, but I am having some difficulty here:

I would like to manually define a DataTemplate to a given ViewModel subtype, but I don't know how to disable the automatic name-based convention.


Solution

  • From "All About Conventions(Caliburn.Micro") documentation:

    Should you decide that you don’t like the behavior of the ViewModelBinder (more details below), it follows the same patterns as the above framework services. It has several Funcs you can replace with your own implementations, such as Bind, BindActions and BindProperties. Probably the most important aspect of customization though, is the ability to turn off the binder’s convention features. To do this, set ViewModelBinder.ApplyConventionsByDefault to false. If you want to enable it on a view-by-view basis, you can set the View.ApplyConventions attached property to true on your View. This attached property works both ways. So, if you have conventions on by default, but need to turn them off on a view-by-view basis, you just set this property to false.