title: How to dynamically load UserControls to TabControl
body: <p>I have several UserControls (in different DLLs) that I am inserting as TabItems into a TabControl of my main Application (EXE). This is the XAML I use to load it and add it to the TabControl:</p>
  
  <pre><code>&lt;TabControl x:Name="mainTabControl"&gt;
      &lt;TabItem Style="{StaticResource VertAlign}" Header="firstDll"&gt;
          &lt;view1:ControlOfTheFirstDll /&gt;
      &lt;/TabItem&gt;
      &lt;TabItem Style="{StaticResource VertAlign}" Header="secondDll"&gt;
          &lt;view2:ControlOfTheSecondDll /&gt;
      &lt;/TabItem&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>Now, I changed my program so that I load each DLL (<code>Data1.dll</code>, <code>Data2.dll</code>) dynamically. With the Startup of my program, an instance of the following class <code>Plugin</code> is created and can be accessed from within my ViewModel.</p>
  
  <pre><code>class Plugin
  {
      [ImportMany]
      public IEnumerable&lt;IDataProvider&gt; DataProvider { get; set; }
  
      public Plugin()
      {
          try
          {
              AggregateCatalog aggregatecatalogue = new AggregateCatalog();               
              aggregatecatalogue.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile("...\\Data1.dll")));
              aggregatecatalogue.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFile("...\\Data2.dll")));
              aggregatecatalogue.Catalogs.Add(new AssemblyCatalog(Assembly.GetAssembly(typeof(IDataProvider))));
  
              CompositionContainer container = new CompositionContainer(aggregatecatalogue);
              container.ComposeParts(this);
          }
          catch (FileNotFoundException fnfex)
          {
              Console.WriteLine(fnfex.Message);
          }
          catch (CompositionException cex)
          {
              Console.WriteLine(cex.Message);
          }
      }
  }
  </code></pre>
  
  <p>Somehow, I need to load the UserControls, which are based in <code>Data1.dll</code> and <code>Data2.dll</code>, dynamically. Something like:</p>
  
  <pre><code>&lt;TabControl x:Name="mainTabControl"&gt;
      &lt;TabItem Style="{StaticResource VertAlign}" Header="firstDll"&gt;
          &lt;ContentControl Content="{Binding PluginInstance.Control.???}" /&gt;
      &lt;/TabItem&gt;
      &lt;TabItem Style="{StaticResource VertAlign}" Header="secondDll"&gt;
          &lt;ContentControl Content="{Binding PluginInstance.Control.???}" /&gt;
      &lt;/TabItem&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>However, I can't seem to get the binding on the control working.</p>