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.
So heres what I've tried. This is my column code.
<DataGridTextColumn Header="{Binding ElementName=frmAssetPPM, Path=HeaderProperty}"
And this is what I've added to the window xaml.
<Window .... Name="frmAssetPPM">
And this is my property definition in the code behind:
private const string HeaderPropertyConstant = "Property";
private string _headerProperty = HeaderPropertyConstant;
public string HeaderProperty
{
get { return _headerProperty; }
set { _headerProperty = value; }
}
However, when I run the application, I'm getting this error message displayed in the Output window in VS.
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')
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.