title: Dynamically toggle visibility of WPF grid column from C# code
body: <p>My problem is: I can't find out how to toggle the visibility of my WPF grid column. Assume following XAML markup:</p>
  
  <pre><code>&lt;Grid x:Name="myGrid"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition x:Name="Row1" /&gt;
          &lt;RowDefinition x:Name="Row2" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition x:Name="Column1" /&gt;
          &lt;ColumnDefinition x:Name="Column2" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Aferwards the grid is filled with some controls etc. Now I want to hide a single column dynamically out of my C# code. I've tried achieving this by setting the the column's definition width to zero, e.g. <code>Column1.Width = 0</code>. This works, but I don't really like this solution - is there really no better way?</p>
  
  <p>I'm looking for something like <code>myGrid.Columns[0].Visibility = COLLAPSED</code> or <code>Column1.Visibility = HIDDEN</code>. I just can't find something like that - any ideas?</p>