title: Bind a WPF datagrid column header to property in code behind
body: <p>Can someone tell me if this is possible. I have a WPF datagrid and I'd like to bind the column headers of the datagrid to properties/fields in the code behind.</p>
  
  <p>So heres what I've tried. This is my column code.</p>
  
  <pre><code>&lt;DataGridTextColumn  Header="{Binding ElementName=frmAssetPPM, Path=HeaderProperty}" 
  </code></pre>
  
  <p>And this is what I've added to the window xaml.</p>
  
  <pre><code>&lt;Window .... Name="frmAssetPPM"&gt;
  </code></pre>
  
  <p>And this is my property definition in the code behind:</p>
  
  <pre><code>private const string HeaderPropertyConstant = "Property";
  private string _headerProperty = HeaderPropertyConstant;
  
  public string HeaderProperty 
  {
      get { return _headerProperty; }
      set { _headerProperty = value; }
  }
  </code></pre>
  
  <p>However, when I run the application, I'm getting this error message displayed in the Output window in VS.</p>
  
  <pre><code>System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=HeaderProperty; DataItem=null; target element is 'DataGridTextColumn' (HashCode=47624635); target property is 'Header' (type 'Object')
  </code></pre>
  
  <p>Can someone tell me what I'm doing wrong? Or if I can even do this? I read somewhere that columns are a separate object and this sometimes leads to complications.</p>