title: WPF Tabcontrol (TabItem Content is not appearing)
body: <p>I implemented a TabControl with Closable TabItems in my App. For this, I am using a Collection which I fill with the SubMenuItems of MenuItem "Öffne", which are bound to ICommands in the MainViewModel. </p>
  
  <p>So if I click on MenuItem "Open Tab1", then the header of Tab 1 is created, but I can not see any content. The content of the TabItem is shown AFTER I click on the Header of the TabItem. But I want it to be shown directly when the TabItem is "created" without any need of clicking on the header. Closing the TabItems from the "X" button works fine. </p>
  
  <p>I looked at a couple of examples and tried a ContentTemplate, but it didn't work (Maybe I made something wrong?). </p>
  
  <p>I Hope you can tell me what i have done wrong or show me a good example.
  Thanks in advance!</p>
  
  <p>Here are my code snippets:</p>
  
  <p>MainWindow.XAML:</p>
  
  <pre><code>&lt;Window.Resources&gt;
  &lt;vm:MainViewModel x:Key="viewModel"/&gt;
  &lt;/Window.Resources&gt;
  &lt;TabControl Background="#FFE5E5E5" ItemsSource="{Binding TabControlViews}" SelectedItem="{Binding CurrentTabItem}" Margin="0,21,0,0"&gt;
          &lt;TabControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;       
                  &lt;DockPanel Width="120"&gt;
                      &lt;TextBlock Text="{Binding Header}"/&gt;
                      &lt;Button
                  Command="{Binding ParameterizedCommand, Source={StaticResource viewModel}}"
                  CommandParameter="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type TabItem}}}"
                  Content="X"
                  Cursor="Hand"
                  DockPanel.Dock="Right"
                  Focusable="False"
                  FontFamily="Courier"
                  FontSize="9"
                  FontWeight="Bold"
                  Margin="0,1,0,0"
                  Padding="0"
                  VerticalContentAlignment="Bottom"
                  Width="16" Height="16" /&gt;
                      &lt;ContentPresenter
                  Content="{Binding Path=DisplayName}"
                  VerticalAlignment="Center" /&gt;
                  &lt;/DockPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ItemTemplate&gt;
          &lt;!--&lt;TabControl.ContentTemplate&gt;
              &lt;DataTemplate&gt;                   
              &lt;/DataTemplate&gt;
          &lt;/TabControl.ContentTemplate&gt;--&gt;
          &lt;TabControl.Resources&gt;
              &lt;DataTemplate x:Name="test" DataType="{x:Type vm:MenueVM}"&gt;
                  &lt;cu:MenueSearch/&gt;
              &lt;/DataTemplate&gt;
              &lt;DataTemplate DataType="{x:Type vm:FieldPointsVM}"&gt;
                  &lt;cu:FieldPointsSearch/&gt;
              &lt;/DataTemplate&gt;
              &lt;DataTemplate DataType="{x:Type vm:DataTransferVM}"&gt;
                  &lt;cu:DataTransfer/&gt;
              &lt;/DataTemplate&gt;
          &lt;/TabControl.Resources&gt;
  &lt;/TabControl&gt;
  </code></pre>
  
  <p>MainWindow.cs:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
  
      public MainWindow()
      {
          InitializeComponent();
          var vm = (MainViewModel)Resources["viewModel"];
          this.DataContext = vm;
      }
  }
  </code></pre>
  
  <p>MainViewModel.cs: </p>
  
  <pre><code>    public MainViewModel()
      {
  
          TabControlViews = new ObservableCollection&lt;BaseViewModel&gt;();
          _menueVM = new MenueVM("Menüpunkte", "Menue");
          _fieldVM = new FieldPointsVM("Feldpunkte", "FieldPoint");
          _dataVM = new DataTransferVM("DatenTransfer", "DataTransfer");
          ParameterizedCommand = new RelayCommand(DoParameterizedCommand);
      }
  
      private void DoParameterizedCommand(object parameter)
      {
          if (parameter.ToString() == "App.ViewModel.MenueVM")
          {
              TabControlViews.Remove(_menueVM);
          }
          else if (parameter.ToString() == "App.ViewModel.FieldPointsVM")
          {
              TabControlViews.Remove(_fieldVM);
          }
          else if (parameter.ToString() == "App.ViewModel.DataTransfer")
          {
              TabControlViews.Remove(_dataVM);
          }
      }
  
      private ICommand _parameterizedCommand;
      public ICommand ParameterizedCommand
      {
          get 
          { 
              return _parameterizedCommand; 
          }
          set
          {
              _parameterizedCommand = value;
          }
      }
  
      private TabItem _propCurrentTabItem;
      public TabItem CurrentTabItem
      {
          get
          {
              return _propCurrentTabItem;
          }
          set
          {
              _propCurrentTabItem = value;
          }
      }
  
      private ObservableCollection&lt;BaseViewModel&gt; _TabControlViews = new ObservableCollection&lt;BaseViewModel&gt;();
      public ObservableCollection&lt;BaseViewModel&gt; TabControlViews
      {
          get
          {
              return _TabControlViews;
          }
          set
          {
              _TabControlViews = value;
              OnPropertyChanged();
          }
      }
  
      public ICommand OpenMenupunkteCommand
      {
          get
          {
              return new BaseCommand(OpenMenuPunkte);
          }
      }
  
      public ICommand OpenFeldpunkteCommand
      {
          get
          {
              return new BaseCommand(OpenFeldpunkte);
          }
      }
  
      public ICommand OpenDataTransferCommand
      {
          get
          {
              return new BaseCommand(OpenDataTransfer);
          }
      }
     private void OpenMenuPunkte()
      {
          if (!TabControlViews.Contains(_menueVM))
          {
              TabControlViews.Add(_menueVM);
          }
  
      }
  
      private void OpenFeldpunkte()
      {
          if (!TabControlViews.Contains(_fieldVM))
          {
              TabControlViews.Add(_fieldVM);
          }
      }
  
      private void OpenDataTransfer()
      {
          if (!TabControlViews.Contains(_dataVM))
          {
              TabControlViews.Add(_dataVM);
          }
      }
  </code></pre>
  
  <p>MenueVM.cs</p>
  
  <pre><code>public class MenueVM : BaseViewModel
  {
  
      public MenueVM()
      {
         //Here are some actions done for Data, but I think they are unimportant for this question
      }
  
      public MenueVM(string header, string content)
      {
          Header = header;
          Content = content;
      }
  
      private string _header;
      public string Header
      {
          get
          {
              return _header;
          }
          set
          {
              _header = value;
          }
      }
  </code></pre>