title: How to collapse a star sized grid column in WPF?
body: <p>Getting three columns have the same width is done by setting <code>Width</code> to <code>Auto</code>.</p>
  
  <pre><code>&lt;Grid x:Name="myGrid"&gt;
    &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition Height="Auto" /&gt;
    &lt;/Grid.RowDefinitions&gt;
  
    &lt;Grid.ColumnDefinitions&gt;
      &lt;ColumnDefinition Width="*" /&gt;
      &lt;ColumnDefinition Width="*" /&gt;
      &lt;ColumnDefinition Width="*" /&gt;
    &lt;/Grid.ColumnDefinitions&gt;
  
    &lt;Label Grid.Row="0" Grid.Column="0"&gt;One&lt;/Label&gt;
    &lt;Label Grid.Row="0" Grid.Column="1" x:Name="label1"&gt;Two&lt;/Label&gt;
    &lt;Label Grid.Row="0" Grid.Column="2"&gt;Three&lt;/Label&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I want to achieve that if middle column is collapsed or hidden that the other two take up remaining space and get equal width. </p>
  
  <p>If I just set Visibility to Collapsed or Hidden because of the Width="*", the other two columns width stays the same.</p>
  
  <pre><code>&lt;Label Grid.Row="0" Grid.Column="1" Visibility="Collapsed"&gt;Two&lt;/Label&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/g9657.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g9657.png" alt="enter image description here"></a></p>
  
  <p>I achieved desired functionality by programatically setting second column width to auto, but am looking for some other solution (preferably xaml way one).</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
  {
    this.myGrid.ColumnDefinitions[1].Width = GridLength.Auto;
    this.label1.Visibility = Visibility.Collapsed;
  }
  </code></pre>