Bind a viewmodel and its view without displaying the view?

Topics: Conventions, Framework Services
Feb 15, 2014 at 8:01 PM
Edited Feb 15, 2014 at 8:02 PM
Given the following:
  • The required target ViewModels are registered in the container.
  • The required target Views are registered in the container.
  • The target views are hosted as individual ContentControls in a main window view.
  • The main window view and its associated VM are registered in the container.
  • The main window VM is started by DisplayRootViewFor<MainWindowVM>().
Is there an entry point (method) in the framework where a target VM could be passed for binding by CM, but not displayed?

I know that I can have each target ViewModel present as a property in the main window VM and CM will bind each VM property, but I am trying to avoid that. In essence, I would like to pass an Ilist<ITargetVM> into the constructor of the main window VM - where ITargetVM is a marker interface - and be able to iterate the list to bind the VMs but not have them displayed.

Feb 18, 2014 at 9:12 AM
CM will try to bind a view-model/model together (hence to display the view) if you either specify the View.Model explicitly, or use naming convention:
public class MyViewModel
        public object MyVMProperty { ... }
<ContentControl x:Name="MyVMProperty"/>
<ContentControl cal:View.Model="{Binding Path=MyVMProperty}"/>
So, if you simply ignore the list property in the view, no control will be generated, since CM naming conventions rely on the fact that exist both a property on the view-model and a control in the view having the same name.