ViewLocator question - catel v3

Apr 23, 2012 at 11:46 PM

Hi,

I am in the process of converting a v2 app to use v3.

I have removed the hookups to the generic DataWindow & Control classes & renamed my 'view' classes to line up with the std naming conventions listed for the view & view model locators. In my case the UserControls are all named [VM]View and all the Windows are named [VM]Window.

I have now hit a snag that I would like some advice about.

I have numerous windows which contain views (usercontrols). IE the control contains most of the vm related controls & the window acts as the 'current' wrapper for the view. This makes it easier to mix views in windows as required.

The snag is that the ViewLocator seems to locate Views before it locates Windows (for a specified view model). EG calling viewLocator.ResolveView(typeof(MyViewModel) returns the type of the usercontrol 'related' the the vm, not the appropriate window.

I assume that [Up].Views.[VM].Views and [UP].Views.[VM].Controls are higher in the 'lookup list' than [UP].Views.[VM]Window, causing the locator to find the View or Control class before the Window class.

I can 'fix' this by manually registering the appropriate Window class for each view model, but this is cumbersome & requires manual updating each time classes are added/edited/removed.

 

What is the best way to get the locator to find the Window classes before the UserControl classes?

Coordinator
Apr 24, 2012 at 6:36 AM

Excellent question, this is a tough one. If you only use the 2 naming conventions, the easiest way is to clear the list and add them yourself:

var viewLocator = GetService<IViewLocator>();
viewLocator.NamingConventions.Clear();
viewLocator.NamingConventions.Add("[UP].Views.[VM]Window");
viewLocator.NamingConventions.Add("[UP].Views.[VM].Controls");
viewLocator.NamingConventions.Add("[UP].Views.[VM].Views");

Apr 24, 2012 at 9:59 AM

Thanks,

I had a suspiscion you might say that... :)

I did try it after I posted the question and indeed it does work. The other option I was considering was to rename the 'views' (user controls) s that the locator doesn't find them.

Would be nice if the locator searched forthe Windows before the other controls though....

Coordinator
Apr 24, 2012 at 10:00 AM

Then you can create an issue with the request, and it might magically implemented in the next version ;)