Bind View to a ViewModel via [View] attribute, is possible?

Topics: Conventions, Extensibility, Getting Started, UI Architecture
Jul 17, 2011 at 4:57 PM

I can't figure out if it possible to use the [View] attribute in Caliburn.Micro?   I've used it in Caliburn but can't figure out how to override a default binding of a View to a ViewModel (not by a name).

Here is an example:  I need to bind   MyViewModel to a AnotherView.   How is it possible?


In Caliburn it was possible to do it this way:


class MyViewModel { }

Any suggestions how to do it in Caliburn.Micro?


Jul 17, 2011 at 7:09 PM

You can easily plug this feature by yourself:
1)  define a simple ViewAttribute with a property aimed to hold the view type
2) customize the ViewLocator.LocateTypeForModelType delegate, making it search the model type for the ViewAttribute. If you find it, just return the view type specified in the attribute; otherwise fall back to the original behavior.

Does it helps?