title: WPF preserve Tab control state
body: <p>I have read the posts @ <a href="https://stackoverflow.com/questions/5038107/how-to-stop-wpf-tabcontrol-to-unload-visual-tree-on-tab-change">How to stop Wpf Tabcontrol to unload Visual tree on Tab change</a>, but I could not get it work, I must have missed something. Pls help. thanks </p>
  
  <p>I am using class TabControlEx from sample project @ <a href="http://www.pluralsight-training.net/community/blogs/eburke/archive/2009/04/30/keeping-the-wpf-tab-control-from-destroying-its-children.aspx" rel="nofollow noreferrer">http://www.pluralsight-training.net/community/blogs/eburke/archive/2009/04/30/keeping-the-wpf-tab-control-from-destroying-its-children.aspx</a> </p>
  
  <pre><code>&lt;Window x:Class="MyMainwindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:sharedC="clr-namespace:myShared.Converter;assembly=myShared"
      xmlns:mainTab="clr-namespace:MyWPFLib.View" Title="{Binding Title}"        
      Height="600" Width="850" Top="223" Left="164" ResizeMode="CanResize" Closing="WindowClosing"
      WindowStyle="ToolWindow"&gt;
  &lt;Grid&gt;
   &lt;mainTab:TabControlEx IsSynchronizedWithCurrentItem="True"
                          Grid.Row="0"  
                          Margin="10 0 5 5"
                          x:Name="MainTabRegion"  
                          TabStripPlacement="Top" 
                          SelectedIndex="{Binding Tabs.SelectedIndex}" 
                          ItemsSource="{Binding Tabs.TabItems}"                         
                          &gt;
                          &lt;TabControl.ItemContainerStyle&gt;
                              &lt;Style TargetType="{x:Type TabItem}"&gt;
                                  &lt;Setter Property="Header"&gt;
                                      &lt;Setter.Value&gt;
                                          &lt;Binding Path="Header"/&gt;
                                      &lt;/Setter.Value&gt;
                                  &lt;/Setter&gt;
                                  &lt;Setter Property="Visibility" 
                                  Value="{Binding IsVisible, Mode=OneWay, Converter={StaticResource boolToVis}}"/&gt;
                              &lt;/Style&gt;
                          &lt;/TabControl.ItemContainerStyle&gt;
                      &lt;/mainTab:TabControlEx&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  
  Datasource for the maintab is Tabs.TabItems
  
      public ObservableCollection&lt;ITabControl&gt; TabItems
      {
          get
          {
              return _items;
          }
      }
  </code></pre>
  
  <p>each TabItem is built with </p>
  
  <pre><code>&lt;DataTemplate DataType="{x:Type vm:Item1ViewModel}"&gt;
      &lt;vw:View1 /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>