如何获取DataGridBoundColumn的绑定路径

时间:2012-04-02 06:08:17

标签: wpf wpf-4.0

我有一个简单的数据网格,我使用ItemsSource绑定一个集合。在我的c#代码中,我不想检索列的绑定路径。我参考了这个专栏。这是我提出的非工作代码

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.

2 个答案:

答案 0 :(得分:3)

你需要向下转向“绑定”。然后你可以访问路径。

答案 1 :(得分:1)

马丁回答的例子。

//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".  
}