I have a datagrid with several DataGridTextColumn defined.
I need to use the Textblock's Tag property. I can't find it on a DataGridTextColumn.
I found a workaround which works, i.e a DataTemplateColumn in which I declare the textblock, in which case I have access to the Tag property:
<DataGridTemplateColumn Header="Column with Tag accessible">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Tag="{Binding Variable1Name}"
Text="{Binding Variable2Name}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
It would be great however if I could achieve the same result with the DataGridTextColumn. Any idea please?
You can't since the
DataGridTextColumnhas noTagproperty that you can set.It's unclear why you need to set the
Tagproperty at all but if you don't want to create aDataGridTemplateColumnand aCellTemplatefor each column, you could create a customDataGridTextColumn:Then you simply replace the built-in
DataGridTextColumnwith this one in your XAML: