0

I'm experimenting and trying to understand the Catel framework.

I understand that Catel has a Naming convention to register Views and viewmodels. According to documentation the [AS] convention, should be replaced by the assembly name. This is not the case for me and I have to manually write the assembly name as follow:

string aSSname = Assembly.GetExecutingAssembly().GetName().Name;
var viewLocator = serviceLocator.ResolveType<IViewLocator>();
viewLocator.NamingConventions.Add(aSSname + ".Views.[VM]Window");

The following code dose NOT work for me:

viewLocator.NamingConventions.Add("[AS]"+ ".Views.[VM]Window");

More Info (if its help):

All the Code above is placed in App.xaml.cs

I load viewModel as separate assembly:

 AppDomain.CurrentDomain.PreloadAssemblies(typeof (App).Assembly.GetDirectory());

to sum up, How can I make this example to work with [AS] convention.

My Guess:

My guess is that viewLocator is looking in the wrong assembly. probably looking in the same assembly were the viewModels are.

if this is right, how can I change the viewLocator so it search in the correct Assembly?

Simon
  • 33,714
  • 21
  • 133
  • 202
RayOldProf
  • 1,040
  • 4
  • 16
  • 40

1 Answers1

1

Catel can only know about the [AS] of the type which is used to resolve the view. So if you are using [AS] in a type in a MyProject.Views assembly, it cannot resolve view models in the MyProject.ViewModels assembly.

In that case you must simply specify the naming convention with the expected assembly name (such as MyProject.Views.[VM]View

You can also do this dynamically yourself by using reflection and resolving all namespaces that contains .Views. in the assemblies that are in the TypeCache of Catel.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32