title: XAML DataTemplate only ever creates one instance
body: <p>The following only ever creates one instance of <code>MyTabView</code>. I've confirmed this by putting a breakpoint in the constructor in MyTabView.xaml.cs. The view is displayed in a tab, and however many tabs I create, I only ever hit that constructor once. </p>
  
  <pre><code>&lt;DataTemplate DataType="{x:Type vm:MyTabViewModel}" x:Shared="false"&gt;
      &lt;vw:MyTabView /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Tab control:</p>
  
  <pre><code>    &lt;TabControl
          Grid.Row="1"
          ItemsSource="{Binding Tabs}"
          SelectedItem="{Binding SelectedTab}"
          &gt;
          &lt;TabControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;TextBlock Text="{Binding DisplayName}" /&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ItemTemplate&gt;
      &lt;TabControl&gt;
  </code></pre>
  
  <p>This causes all the tabs to reflect share any state that's not bound to a view model: If you move a <code>GridSplitter</code>, that's the same <code>GridSplitter</code> in all the other tabs, so it appears to the user that you moved all of them. It's absurd. </p>
  
  <p>I don't understand. Is there any way to use <code>TabControl</code> with multiple items of the same type? </p>
  
  <p>EDIT: Added <code>x:Shared="false"</code> to <code>DataTemplate</code>. </p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>So I've found a couple of fixes, but I don't like them very much. I'm going to take a look at writing a Converter that converts <code>ObservableCollection&lt;Object&gt;</code> to <code>ObservableCollection&lt;TabItem&gt;</code> -- kind of like a live-updated version of</p>
  
  <pre><code>coll.Select(vm =&gt; new TabItem() { Content = vm });
  </code></pre>
  
  <p>...but we'll see whether or not it likes getting <code>TabItem</code> instances from <code>ItemsSource</code>. My money says don't bet on it. But we'll see. </p>
  
  <p><strong>UPDATE 2:</strong> Took a while to get back to this. The gimmick with swapping in a collection of tab items works, though <code>SelectedItem</code> is problem. Turns out there's another solution (below) that doesn't create that issue, and also avoids the complexity and goofiness of creating a "middleman" collection that has to mirror changes in the source collection. </p>