title: In Prism (Composite Application Guidelines), how can I get views dynamically loaded into TabControl?
body: <p>In a Prism v2 application, I define two regions, each a tabitem in a tabcontrol:</p>
  
  <pre><code>&lt;UniformGrid Margin="10"&gt;
      &lt;TabControl&gt;
          &lt;TabItem Header="First" Name="MainRegion" cal:RegionManager.RegionName="MainRegion"/&gt;
          &lt;TabItem Header="Second" Name="SecondRegion" cal:RegionManager.RegionName="SecondRegion"/&gt;
      &lt;/TabControl&gt;
  &lt;/UniformGrid&gt;
  </code></pre>
  
  <p>In the bootstrapper two modules are loaded and each injects a view into each of the tabitems:</p>
  
  <pre><code>protected override IModuleCatalog GetModuleCatalog()
  {
      ModuleCatalog catalog = new ModuleCatalog();
      catalog.AddModule(typeof(SecondModule.SecondModule));
      catalog.AddModule(typeof(HelloWorldModule.HelloWorldModule));
      return catalog;
  }
  </code></pre>
  
  <p>Now, of course, I want to perform the decoupling magic that I keep reading about and uncomment one of the modules and see its tab item not appear at all. Instead, on the contrary, there are still two TabItems and one is empty. This tells me that my application is still tightly coupling data and UI as in the bad old WinForm days.</p>
  
  <p>So what do I need to do here to make this dynamic, so that the UI changes dynamically based on what modules are loaded, i.e. so that I could load 10 modules/views in my bootstrapper and there would automatically be 10 TabItems in the TabControl?</p>
  
  <h2>INTERMEDIATE ANSWER:</h2>
  
  <p>If I just make one region in a TabControl:</p>
  
  <pre><code>&lt;TabControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion"/&gt;
  </code></pre>
  
  <p>and then load both controls into the MainRegion:</p>
  
  <pre><code>        public void Initialize()
          {
              regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.SecondView));
          }
  ...
          public void Initialize()
          {
              regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.HelloWorldView));
          }
  </code></pre>
  
  <p>then I get a TabControl with two tabs, each with a view in it, which is what I want.</p>
  
  <p>But the TabItem headers are not defined. How do I dynamically define the header (e.g. not in the XAML but dynamically back in the View classes)?</p>