3

In my xaml I have modified each column header to include a button. For the command parameter I would like to use the column's data field name, instead of the header content. E.g. Instead of "Job Title" which is what the header content is, I want "JOB_TITLE".

For header content I would use:

<Button Command="{Binding DataContext.OpenFilterCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{TemplateBinding Content}">

How do I get the actual field name?

Hank
  • 2,456
  • 3
  • 35
  • 83

1 Answers1

5

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)

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • Also you seem to know your way around paths and noone has been able to give me an answer to this. http://stackoverflow.com/questions/20976894/how-to-set-datatrigger-parameter-to-collection-sitting-in-parent – Hank Jan 26 '14 at 00:26
  • I have a very related issue to this one. Where {Binding Column.Binding.Path.Path is throwing error. This is occurring on a DataGridComboBoxColumn, the structure is different. Raised a new question for it: http://stackoverflow.com/questions/22804196/how-to-bind-property-name-to-which-column-is-binded-to-pass-as-command-parameter – Hank Apr 02 '14 at 07:20