1. 程式人生 > >WPF:後臺獲取DataGrid列的繫結欄位。

WPF:後臺獲取DataGrid列的繫結欄位。

前臺:

 <DataGrid Name="dg" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=id}"/>
                <DataGridTextColumn Binding="{Binding Path=name}"/>
            </DataGrid.Columns>
        </DataGrid>

後臺:
  DataGridTextColumn dgcol = dg.Columns[0] as DataGridTextColumn;
            Binding binding = dgcol.Binding as Binding;
            string path = binding.Path.Path;