tl;dr I have a DataGrid, and I'm binding the row headers. However, I can't get this to work with the StringFormat
property on the binding.
I've got a WPF DataGrid set up like this:
<DataGrid HeadersVisibility="All"
ItemsSource="{Binding Data}">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Header" Value="{Binding Lane, StringFormat=Lane {0:0}}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Value1}" Header="Value 1" />
<DataGridTextColumn Binding="{Binding Value2}" Header="Value 2" />
<DataGridTextColumn Binding="{Binding Value3}" Header="Value 3" />
<DataGridTextColumn Binding="{Binding Value4}" Header="Value 4" />
</DataGrid.Columns>
</DataGrid>
But no matter what I do, I can't get the StringFormat
property to work properly on the DataGridRow
header. All it shows is the number that I've bound, and not the format text. But, if I put the same format string on a TextBlock
, it works perfectly.
<TextBlock Text="{Binding Lane, StringFormat=Lane {0:0}}"/>
Does anyone know why the StringFormat
property isn't used properly? Is there a way I can get the behaviour I want?
Edit: This is what the Lane property looks like.
public int Lane {
get { return lane; }
set {
lane = value;
NotifyPropertyChanged();
}
}