Multiples views - viewModel mapping, with custom naming conventions

Topics: Bootstrappers & IoC, Conventions
Jan 21, 2014 at 2:34 PM
Edited Jan 21, 2014 at 3:58 PM
Hi,
Here's my problem:
I have a ViewModel which should be displayed in two locations at the same time, using two differents views (a mainView and a ToolBarView).
So I had 3 files:
  • SomeWorkspace.MyViewModel
  • SomeWorkspace.MyView
  • SomeWorkspace.My.ToolBarView
<ContentControl cal:View.Model="{Binding MyViewModel" cal:View.Context="ToolBarView"/>
Everything worked fine, ToolBarView and MyView were displayed correctly.

Yesterday, I needed to support a new ViewModel naming: MyViewModel => MyDocument, but MyViewModel should still be supported.
So I added a rule in the BootStrapper.Configure():
ViewLocator.NameTransformer.AddRule("Document$", "View");
Now the ToolBar isn't displayed anymore (but MyView is).
The arborescence is:
  • SomeWorkspace.MyDocument
  • SomeWorkspace.MyView
  • SomeWorkspace.My.ToolBarView
I'm trying to figure out what happens, but in debug mode I already saw that the documentRule is messing up the ToolBar location.

Can someone helps me ? Maybe the way I added the rule was bad, I'm still on it at the moment.

You can easily reproduce the problem, but I can upload a sample project somewhere if you need.

Thanks,

Ph

EDIT: To handle the "Document" suffix for a ViewModel, my first tought wasn't to add a rule but to add a ViewModelSuffix. E.g, if instead of
ViewLocator.NameTransformer.AddRule("Document$", "View");
I do:
            var config = new TypeMappingConfiguration()
                         {
                             ViewModelSuffix = "Document",
                             IncludeViewSuffixInViewModelNames = false
                         };
            ViewLocator.ConfigureTypeMappings(config);
            ViewModelLocator.ConfigureTypeMappings(config);
Both the document AND the ToolBar works, but all the ViewModel which are named "MyViewModel" and not "MyDocument" can't find their view (remember I have to handle both cases). I don't understand why there isn't a ViewModelSuffixList ? Especially when there is a ViewSuffixList