title: setting datacontext for a view in a tab item
body: <p>in my window resources i have a datatemplate for my viewmodel and a static mainviewmodel</p>
  
  <pre><code>&lt;Window.Resources&gt;
          &lt;DataTemplate DataType="{x:Type SharedViewModels:DatabaseViewModel}"&gt;
              &lt;SharedViews:DatabaseView/&gt;
          &lt;/DataTemplate&gt;
  
          &lt;LocalViewModels:SharedSettingsViewModel x:Key="SharedSettingsViewModel"/&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p><code>DatabaseViewModel</code> is an instance in my static <code>SharedSettingsViewModel</code>
  and i have this tab control</p>
  
  <pre><code>&lt;TabControl DataContext="{Binding Source={StaticResource SharedSettingsViewModel}}" ItemsSource="{Binding SharedSettingsViewModelsTabList}"&gt;
                          &lt;TabControl.ItemTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;ContentPresenter Content="{Binding Content}"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/TabControl.ItemTemplate&gt;
                      &lt;/TabControl&gt;
  </code></pre>
  
  <p>and i add items to my TabControl itemssorce like this</p>
  
  <pre><code>SharedSettingsViewModelTabList.Add(new Shared.Models.TabItem() { Header = "Sql Databases", Content = DatabaseViewModel });
  </code></pre>
  
  <p>How do set the datacontext of my <code>DatabaseView</code> to the <code>DatabaseViewModel</code> instance that is inside my <code>SharedSettingsViewModel</code>?</p>
  
  <p>in my view DatabaseView XAML  which is a user control i tried</p>
  
  <pre><code>DataContext="{Binding DatabaseViewModel}"
  </code></pre>
  
  <p>but this doesnt seem to work</p>
  
  <p>here is my TabItem Model</p>
  
  <pre><code>public class TabItem : MVVM.ObservableObject
      {
          public string Header { get; set; }
          public MVVM.ObservableObject Content { get; set; }
      }
  </code></pre>
  
  <p>my DatabaseViewModel which will be defined as a Property in SharedSettingsViewModel</p>
  
  <pre><code> private ObservableCollection&lt;Models.Database&gt; databases;
  
   public ObservableCollection&lt;Models.Database&gt; Databases
          {
              get
              {
                  if (databases == null)
                  {
                      databases = new ObservableCollection&lt;Models.Database&gt;();
                      databases.Add(new Models.Database() { Displayname = "new" });
                  }
                  return databases;
              }
              set
              {
                  SetField(ref databases, value, "Databases");
              }
          }
  </code></pre>
  
  <p>and here is my SharedSettingsViewModel which contains the tab items collection</p>
  
  <pre><code>public class SharedSettingsViewModel : MVVM.ObservableObject 
      {
      private ObservableCollection&lt;Shared.Models.TabItem&gt; SharedSettingsViewModelTabList;
      public ObservableCollection&lt;Shared.Models.TabItem&gt; SharedSettingsViewModelTabList
              {
                  get
                  {
                      if (sharedSettingsViewModelTabList == null)
                      {
                          sharedSettingsViewModelTabList = new ObservableCollection&lt;Shared.Models.TabItem&gt;();
                      }
                      return sharedSettingsViewModelTabList;
                  }
  
              }
  
      //my DatabaseViewModel property..as a child view model
  
              private Shared.ViewModels.DatabaseViewModel databaseViewModel;
              public Shared.ViewModels.DatabaseViewModel DatabaseViewModel
              {
                  get
                  {
                      if (databaseViewModel == null)
                      {
                          databaseViewModel = new Shared.ViewModels.DatabaseViewModel();
                      }
                      return databaseViewModel;
                  }
                  set
                  {
                      SetField(ref databaseViewModel, value, "DatabaseViewModel");
                  }
              }
  }
  </code></pre>