2012-04-02 85 views
1

我有一個簡單的數據網格,我使用ItemsSource綁定了一個集合。在我的C#代碼中,我不想檢索列的綁定路徑。我參考了專欄。這裏是我提出的非工作代碼如何獲得DataGridBoundColumn的綁定路徑

DataGridBoundColumn column = getColumn() //function to get column. Already working 
BindingBase binding = column.Binding; //get the binding 
PropertyPath path = //how to get the path from binding. 

回答

1

您需要沮喪爲「綁定」。然後你可以訪問路徑。

+0

非常感謝。這真的很快。 – Jatin 2012-04-02 06:17:54

0

馬丁回答的例子。

//Ex: In xaml <DataGridTextColumn Binding="{Binding column1}"/> 

foreach (DataGridBoundColumn c in myGrid.Columns) 
{ 
    Binding b = (Binding)c.Binding; //Two different binding types. 
    MessageBox.Show(b.Path.Path); //Returns "column1". 
}