title: How do you resize TabControl when you resize window manually, maximize, or restore
body: <p>I am using WPF with MVVM pattern. How do I resize WPF TabControl when you manually resize Main window? TabControl should also resize when you maximize or restore. Can you please explain the logic as put solution? Can you please suggest me reading topic which is associated with this logic. 
  On the code below, I am TabControl to achive MDI look and feel, where UserControl gets added to TabControl. </p>
  
  <h2>DashboardView.xaml</h2>
  
  <pre><code> &lt;Window x:Class="MyProject.DashboardView"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:local="clr-namespace:MyProject"
           Title="Resiable tabcontrol" 
           Width="1064"
           Height="897" 
  
           WindowState="Normal" 
           WindowStartupLocation="CenterOwner"&gt;
  
      &lt;Window.Resources&gt;
      &lt;local:TabSizeConverter x:Key="tabSizeConverter" /&gt;
      &lt;Style TargetType="{x:Type TabItem}"&gt;
          &lt;Setter Property="Width"&gt;
              &lt;Setter.Value&gt;
                  &lt;MultiBinding Converter="{StaticResource tabSizeConverter}"&gt;
                      &lt;Binding RelativeSource="{RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type TabControl}}" /&gt;
                      &lt;Binding RelativeSource="{RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type TabControl}}" Path="ActualWidth" /&gt;
  
                  &lt;/MultiBinding&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
      &lt;/Window.Resources&gt;
  
     &lt;DockPanel&gt;
  
      &lt;Menu Name="menu1" VerticalAlignment="Top" Visibility="Visible" 
          DockPanel.Dock="Top" Loaded="menu1_Loaded"&gt;
          &lt;Menu.Background&gt;
              &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,0"&gt;
                  &lt;LinearGradientBrush.GradientStops&gt;
                      &lt;GradientStop Offset="0" Color="White"/&gt;
                      &lt;GradientStop Offset="0" Color="White"/&gt;
                  &lt;/LinearGradientBrush.GradientStops&gt;
              &lt;/LinearGradientBrush&gt;
          &lt;/Menu.Background&gt;
  
          &lt;MenuItem Header="File" Name="mnuTab" &gt;
              &lt;MenuItem Header="List of High School" 
                 Click="mnuTab1_Click"/&gt;
              &lt;MenuItem Header="List of University" 
                 Click="mnuTab2_Click" InputGestureText="Ctrl-U" /&gt;
  
              &lt;MenuItem Header="Exit" Click="mnuExit_Click" /&gt;
          &lt;/MenuItem&gt;
  
       &lt;/Menu&gt;
  
       &lt;Grid Width="Auto" Height="Auto" &gt;
          &lt;TabControl  Name="tcMdi" Visibility="Visible" HorizontalAlignment="Left" 
             VerticalAlignment="Top" ScrollViewer.HorizontalScrollBarVisibility="Auto" 
            ScrollViewer.VerticalScrollBarVisibility="Auto" &gt;
              &lt;TabControl.Background&gt;
                  &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,0"&gt;
                      &lt;LinearGradientBrush.GradientStops&gt;
                          &lt;GradientStop Offset="0" Color="White" /&gt;
                          &lt;GradientStop Offset="0" Color="White" /&gt;
                      &lt;/LinearGradientBrush.GradientStops&gt;
                  &lt;/LinearGradientBrush&gt;
              &lt;/TabControl.Background&gt;
             &lt;/TabControl&gt;
           &lt;/Grid&gt;
         &lt;/DockPanel&gt;
       &lt;/Window&gt;
  </code></pre>
  
  <h2>DashboardView.xaml.cs</h2>
  
  <pre><code> namespace MyProject
   {
      public partial class DashboardView : Window
      {
      private Dictionary&lt;string, string&gt; _mdiChildren = new Dictionary&lt;string, string&gt;();
      public DashboardView()
      {
          InitializeComponent();
          WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; 
      }
  
      private void mnuTab1_Click(object sender, RoutedEventArgs e)
      {
          ListOfHighSchoolView mdiChild = new ListOfHighSchoolView ();
          AddTab(mdiChild);
          txtBackground.Visibility = Visibility.Hidden;
      }
  
      private void mnuTab2_Click(object sender, RoutedEventArgs e)
      {
  
          ListOfHighUniversityView mdiChild = new ListOfHighUniversityView ();
          AddTab(mdiChild);
          txtBackground.Visibility = Visibility.Hidden;
      }
  
       private void mnuExit_Click(object sender, RoutedEventArgs e)
      {
          Application.Current.Shutdown();
      }
  
      // Add tab item to the tab
      //This is the user control 
      private void AddTab(ITabbedMDI mdiChild)
      {
          //Check if the user control is already opened
          if (_mdiChildren.ContainsKey(mdiChild.UniqueTabName))
          {
              //user control is already opened in tab. 
              //So set focus to the tab item where the control hosted
              foreach (object item in tcMdi.Items)
              {
                  TabItem ti = (TabItem)item;
                  if (ti.Name == mdiChild.UniqueTabName)
                  {
                      ti.Focus();
                      break;
                  }
              }
          }
          else
          {
              //the control is not open in the tab item
              tcMdi.Visibility = Visibility.Visible;
  
              tcMdi.Width = this.ActualWidth;
              tcMdi.Height = this.ActualHeight;
  
  
              ((ITabbedMDI)mdiChild).CloseInitiated += new delClosed(CloseTab);
  
              //create a new tab item
              TabItem ti = new TabItem();
              //set the tab item's name to mdi child's unique name
              ti.Name = ((ITabbedMDI)mdiChild).UniqueTabName;
              //set the tab item's title to mdi child's title
              ti.Header = ((ITabbedMDI)mdiChild).Title;
              //set the content property of the tab item to mdi child
              ti.Content = mdiChild;
              ti.HorizontalContentAlignment = HorizontalAlignment.Stretch;
              ti.VerticalContentAlignment = VerticalAlignment.Top;
              //add the tab item to tab control
              tcMdi.Items.Add(ti);
              //set this tab as selected
              tcMdi.SelectedItem = ti;
              //add the mdi child's unique name in the open children's name list
              _mdiChildren.Add(((ITabbedMDI)mdiChild).UniqueTabName, ((ITabbedMDI)mdiChild).Title);
  
          }
      }
  
      private void CloseTab(ITabbedMDI tab, EventArgs e)
      {
          TabItem ti = null;
          foreach (TabItem item in tcMdi.Items)
          {
              if (tab.UniqueTabName == ((ITabbedMDI)item.Content).UniqueTabName)
              {
                  ti = item;
                  break;
              }
          }
          if (ti != null)
          {
              _mdiChildren.Remove(((ITabbedMDI)ti.Content).UniqueTabName);
              tcMdi.Items.Remove(ti);
              txtBackground.Visibility = Visibility.Visible;
          }
      }
  
      // Adjust the tab height and weight during load
      private void menu1_Loaded(object sender, RoutedEventArgs e)
      {
          tcMdi.Width = this.ActualWidth;
          tcMdi.Height = this.ActualHeight - 10;
      }
    }
  }
  </code></pre>
  
  <h2>Converters.cs</h2>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Windows.Controls;
  
  namespace MyProject
  {
    public class TabSizeConverter : System.Windows.Data.IMultiValueConverter     
    {         
      public object Convert(object[] values, Type targetType, object parameter, 
       System.Globalization.CultureInfo culture)         
      {             
          TabControl tabControl = values[0] as TabControl;             
          double width = tabControl.ActualWidth / tabControl.Items.Count;             
          //Subtract 1, otherwise we could overflow to two rows.             
          return (width &lt;= 1) ? 0 : (width - 1);         
      }    
  
      public object[] ConvertBack(object value, Type[] targetTypes, object parameter, 
      System.Globalization.CultureInfo culture)         
      {             
          throw new NotSupportedException();         
      }     
    } 
  }
  </code></pre>