Caliburn and namespaces

Nov 7, 2011 at 9:20 AM

Hello,

I've followed the tutorial and in first I've done as usual putting the ViewModel under the namespace xxx.ViewModels, running at first I got an exception and I've realized that Caliburn resolves automatically the ViewModel adding Model to the name of the Xaml..... what if I add the models under a folder? have I to rename each class I create setting the namespace equal to the one of the view

If I don't want to use this feature of Caliburn, what should I do, set in the View the datacontext?

Thanks

 

Coordinator
Nov 7, 2011 at 6:15 PM

First off, Caliburn Micro is a ViewModel first framework. So it resolves the View based on the ViewModel and not the other way around. Yes, with the out of the box conventions the folder structure between the ViewModels and Views need to mirror each other with the difference that where you use ViewModels/ViewModel in the name it has to be Views/View for the view.

For example:

ViewModel: a.b.c.d.ViewModels.MyViewModel

View: a.b.c.d.Views.MyView

If you just want them to be in the same folder you can do that with the out-of-the-box conventions. Just don't use Views/ViewModels in the namespace.

For example:

ViewModel: a.b.c.d.MyViewModel

View: a.b.c.d.MyView

As with all the conventions in CM, you can define your own convention for the ViewModel/View mapping if you don't like the out-of-the-box conventions. In version 1.1, CM introduced the NameTransformer. It's based on regular expressions. Take a look at the documentation here:

http://caliburnmicro.codeplex.com/wikipage?title=Using%20the%20NameTransformer&referringTitle=Documentation