2009-12-29 178 views
1
DataGridTextColumn col = new DataGridTextColumn(); 

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

我想綁定PROPERTYNAME爲每列WPF的DataGrid列

foreach (DataGridTextColumn column in grd.Columns) 
    { 

    } 

如何實現這一目標?

回答

1
foreach (DataGridTextColumn column in grd.Columns) 
{ 
    Binding binding = column.Binding as Binding; 
    string propertyName = null; 
    if (binding != null) 
     propertyName = binding.Path.Path; 
} 
+0

沒有屬性column.Binding.Path.Path; 我需要獲取該列綁定的屬性名稱。 在我的情況下,我想要獲取Text1(綁定) – Dee 2009-12-29 13:53:54

+0

修復了代碼,我錯誤地認爲'Binding'屬性的類型是'Binding',而不是基類型'BindingBase'。 – 2009-12-29 14:01:24

+0

上面的代碼工作。謝謝 – Dee 2009-12-30 06:16:21