title: wpf toggling visibility collapse only works once
body: <p>What i want to do is collapse the bottom section of the WPF ui based on the checkbox toggle. This mostly works as expected so far. Below as you step through the images you'll see the collapse stops working once the grid splitter is moved. I do not understand why or how to fix this.</p>
  
  <p>Start of the application, appears correct.</p>
  
  <p><a href="https://i.stack.imgur.com/e0man.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e0man.png" alt="Initial opening of the application"></a></p>
  
  <p>Toggle the checkbox and the botttom section disappears as expected.</p>
  
  <p><a href="https://i.stack.imgur.com/fn3Hy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fn3Hy.png" alt="enter image description here"></a></p>
  
  <p>Toggle the checkbox once more and then move the splitter vertically, everything appears as expected.</p>
  
  <p><a href="https://i.stack.imgur.com/Srrum.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Srrum.png" alt="enter image description here"></a></p>
  
  <p>Now toggle the checkbox one last time and you'll notice the top section doesn't fill the application like it once did before. This is where it appears broken! I would expect the yellow section to fill the UI like it did in the initial toggle. </p>
  
  <p><a href="https://i.stack.imgur.com/amj12.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/amj12.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="250" Width="525"
          WindowStartupLocation="CenterScreen"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;CheckBox Name="ToggleVisibility" Margin="10" IsChecked="True" Content="Toggle Bottom Section"&gt;&lt;/CheckBox&gt;
  
          &lt;StackPanel Background="#feca00" Grid.Row="1"&gt;
              &lt;TextBlock FontSize="20" Foreground="#58290A"&gt;Top Section&lt;/TextBlock&gt;
          &lt;/StackPanel&gt;
  
          &lt;GridSplitter Grid.Row="2" Height="5" HorizontalAlignment="Stretch"&gt;
              &lt;GridSplitter.Style&gt;
                  &lt;Style TargetType="GridSplitter"&gt;
                      &lt;Setter Property="Visibility" Value="Visible" /&gt;
                      &lt;Setter Property="Background" Value="Red" /&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding ElementName=ToggleVisibility, Path=IsChecked}" Value="False"&gt;
                              &lt;Setter Property="Visibility" Value="Collapsed"&gt;&lt;/Setter&gt;
                              &lt;Setter Property="Background" Value="Red"&gt;&lt;/Setter&gt;
                          &lt;/DataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/GridSplitter.Style&gt;
          &lt;/GridSplitter&gt;
  
          &lt;StackPanel Grid.Row="3" Background="LightBlue"&gt;
              &lt;StackPanel.Style&gt;
                  &lt;Style TargetType="StackPanel"&gt;
                      &lt;Setter Property="Visibility" Value="Visible" /&gt;
                      &lt;Setter Property="Background" Value="Red" /&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding ElementName=ToggleVisibility, Path=IsChecked}" Value="False"&gt;
                              &lt;Setter Property="Visibility" Value="Collapsed"&gt;&lt;/Setter&gt;
                              &lt;Setter Property="Background" Value="Red"&gt;&lt;/Setter&gt;
                          &lt;/DataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/StackPanel.Style&gt;
  
              &lt;TextBlock FontSize="20" Foreground="black"&gt;Bottom Section&lt;/TextBlock&gt;
          &lt;/StackPanel&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>