My question is similar to Why DataColumn.Caption doesn't work?, but for WPF. I have a DataGrid
bound to a DataTable
using an MVVM pattern. The DataGrid
has AutoGenerateColumns = true
. How do I bind the DataGridColumn header text to the DataColumn.Caption
instead of DataColumn.ColumnName
? I was hoping for a solution like this:
<DataGrid ItemsSource="MyDataTable" AutoGenerateColumns="true">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding DataColumn.Caption}"> <!--this does not work-->
...
</DataGrid>