How to get field that datagrid column is bound to?

佐手、 提交于 2019-12-06 03:27:09

If i assume it right you want binding property name to which column is binded to pass as command parameter to OpenFilterCommand.

Suppose columns are like this for your DataGrid:

        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding NAME}"/>
            <DataGridTextColumn Binding="{Binding JOB_TITLE}" />
        </DataGrid.Columns>

and want to pass property name JOB_TITLE as command parameter. This can be achieve like this:

<Button Command="{Binding DataContext.OpenFilterCommand,
                     RelativeSource={RelativeSource AncestorType=UserControl}}"
        CommandParameter="{Binding Column.Binding.Path.Path,
                     RelativeSource={RelativeSource Mode=TemplatedParent}}"/>

EXPLANATION

TemplatedParent (DataGridColumnHeader) --> Column (DataGridTextColumn) --> Binding (BindingBase) --> Path (PropertyPath) --> Path (Actual PropertyName)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!