2

我有一个简单的数据网格,我使用 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.
4

2 回答 2

3

您需要向下转换为“绑定”。然后就可以访问路径了。

于 2012-04-02T06:11:24.193 回答
2

马丁回答的例子。

//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".  
}
于 2017-06-18T00:58:35.033 回答