title: Binding Visibility for DataGridColumn in WPF
body: <p>How can I hide a column in a WPF <code>DataGrid</code> through a Binding?</p>
  
  <p>This is what I did:</p>
  
  <pre><code>&lt;DataGridTextColumn Header="Column header"
                      Binding="{Binding ColumnValue}"
                      Width="100"
                      ElementStyle="{StaticResource DataGridRightAlign}"
                      Visibility="{Binding MyColumnVisibility}" /&gt;
  </code></pre>
  
  <p>And this is what I got (besides the column still visible):</p>
  
  <blockquote>
    <p>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=MyColumnVisibility; DataItem=null; target element is 'DataGridTextColumn' (HashCode=1460142); target property is 'Visibility' (type 'Visibility')</p>
  </blockquote>
  
  <p>How to fix the binding?</p>