title: How to inject a view into a region via view model at program start
body: <p>I am creating a WPF MVVM Prism application where I need to switch between views within a region, which I do with view injection. I instantiate the Region in <code>MainWindow.xaml</code> like this:</p>
  <pre><code>&lt;ContentControl prism:RegionManager.RegionName=&quot;ContentRegion&quot; /&gt;
  </code></pre>
  <p>Changing the views with commands later is no problem. The problem is that I need the region at program start to be able to show a view from the beginning. When I put that in the constructor like</p>
  <pre><code>public MainWindowViewModel(IContainerExtension container, IRegionManager regionManager)
  {
     _regionManager = regionManager;
     _container = container;
  
     _view1 = _container.Resolve&lt;1Control&gt;();
     _view2 = _container.Resolve&lt;2Control&gt;();
     _contentregion = _regionManager.Regions[&quot;ContentRegion&quot;];
     _contentregion.Add(_view1);
     _contentregion.Add(_view1);
  }
  </code></pre>
  <p>I get the error that <code>RegionManager</code> does not contain <code>ContentRegion</code>. This is the case because it is not yet instantiated from XAML at that time.  I cannot use the main window and the <code>Loaded</code> event like <a href="https://github.com/PrismLibrary/Prism-Samples-Wpf/tree/master/06-ViewActivationDeactivation/ActivationDeactivation" rel="nofollow noreferrer">here</a>, because I need to do it in the view model, instead of code-behind. It would also be enough to have a default view set somehow (in XAML Maybe?) and then later change the active view with commands, but I also don't see how that could work.</p>