title: WPF Expander with GridSplitter
body: <p>In my WPF window (.NET 4.0) I have Grid with two columns: stretched textbox (or whatever) on the left side and Expander on the right. Also in Expander I have GridSplitter, which is intended to resize both left and right columns when Expander is expanded. But it doesn't work.</p>
  
  <p>This is my XAML code:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication10.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid ShowGridLines="True" &gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition /&gt;
          &lt;ColumnDefinition Width="Auto" Name="column"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;TextBox Grid.Column="0" HorizontalAlignment="Stretch" TextWrapping="Wrap" 
               Text="TextBox" VerticalAlignment="Stretch" Background="Aqua"/&gt;
  
      &lt;Expander Grid.Column="1" Header="Expander" ExpandDirection="Left" 
                HorizontalAlignment="Right" Background="LightBlue" &gt;
          &lt;Expander.Content&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="5"/&gt;
                      &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;TextBlock Text="Some text Some text Some Text" Grid.Column="1"/&gt;
                  &lt;GridSplitter Grid.Column="0" Width="5"    
                                ResizeBehavior="PreviousAndCurrent"
                                ResizeDirection="Columns" 
                                HorizontalAlignment="Stretch"/&gt;
              &lt;/Grid&gt;
          &lt;/Expander.Content&gt;
      &lt;/Expander&gt;
  &lt;/Grid&gt;&lt;/Window&gt;
  </code></pre>
  
  <hr>
  
  <p>Appropriate solution is found. 
  XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication10.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525"&gt;
  
  &lt;Window.Resources&gt;
      &lt;BooleanToVisibilityConverter x:Key="BoolToVisConverter"/&gt;
  &lt;/Window.Resources&gt;
  
  &lt;Grid ShowGridLines="True"&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*" Name="leftColumn"/&gt;
          &lt;ColumnDefinition Width="Auto"/&gt;
          &lt;ColumnDefinition Width="Auto" Name="rightColumn" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;TextBox Grid.Column="0"
               HorizontalAlignment="Stretch"
               TextWrapping="Wrap"
               Text="TextBox"
               VerticalAlignment="Stretch"
               Background="Aqua" /&gt;
  
      &lt;Expander Grid.Column="2"
                Name="Expander"
                Header="Expander"
                ExpandDirection="Left"
                Background="LightBlue" 
                Collapsed="Expander_Collapsed" 
                Expanded="Expander_Expanded" &gt;
          &lt;TextBlock Text="Some text Some text Some Text" /&gt;
      &lt;/Expander&gt;
      &lt;GridSplitter Grid.Column="1"
                    Width="5"
                    ResizeBehavior="PreviousAndNext"
                    ResizeDirection="Columns"
                    VerticalAlignment="Stretch"
                    Height="Auto" 
                    Visibility="{Binding ElementName=Expander, Path=IsExpanded, 
                                Converter={StaticResource BoolToVisConverter}}"/&gt;
  &lt;/Grid&gt;&lt;/Window&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>    private void Expander_Collapsed(object sender, RoutedEventArgs e)
      {
          leftColumn.Width = new GridLength(1, GridUnitType.Star);
          rightColumn.Width = new GridLength(1, GridUnitType.Auto);
      }
  
      private void Expander_Expanded(object sender, RoutedEventArgs e)
      {
          rightColumn.Width = new GridLength(1, GridUnitType.Star);
      }
  </code></pre>