I'm binding the columnheaders of a datagrid to an observablecollection of dates, to display the day and date in the columnheader. This works fine. However, I would like to add a newline or break using the string. How can this be done?
<DataGridTextColumn>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding DataContext.Week.Days[1].Date, StringFormat=ddd dd.MM.yyyy, RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
This displays the following Text: Tue 06.12.2016 What I want it to display is
Tue
06.12.2016
For folks looking to put a newline in StringFormat (or ContentStringFormat, if you need to use Label), this answer has a way. You can use:
HEX represenation of CR/LF


(or just line feed

):
So, for the code in question:
StringFormat=ddd
dd.MM.yyyy
Set the TextBlock's Inlines
property:
<TextBlock DataContext="{Binding DataContext.Week.Days[1].Date,
RelativeSource={RelativeSource AncestorType=DataGrid}}">
<Run Text="{Binding Mode=OneWay, StringFormat=ddd}"/>
<LineBreak/>
<Run Text="{Binding Mode=OneWay, StringFormat=dd.MM.yyyy}"/>
</TextBlock>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With