tags:

views:

34

answers:

1
DataGridTextColumn col = new DataGridTextColumn();

col.Header = "Text1";
col.Binding = new System.Windows.Data.Binding("Text1");  
grd.Columns.Add(col);

I want to get the Binding propertyname for each column

foreach (DataGridTextColumn column in grd.Columns)
  {

  }

How do I achieve this?

+1  A: 
foreach (DataGridTextColumn column in grd.Columns)
{
    Binding binding = column.Binding as Binding;
    string propertyName = null;
    if (binding != null)
        propertyName = binding.Path.Path;
}
Aviad P.
There is no property column.Binding.Path.Path;I need to get the property name to which the column is bound.In my case I want to get Text1(Binding)
Dee
Fixed the code, I mistakenly assumed the `Binding` property was of type `Binding`, it was of the base type `BindingBase` instead.
Aviad P.
The above code works.Thanks
Dee