Multiples views - viewModel mapping, with custom naming conventions

Topics: Bootstrappers & IoC, Conventions
Jan 21, 2014 at 3:34 PM
Edited Jan 21, 2014 at 4:58 PM
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.



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
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