Jul Pod Jul Pod - 1 year ago 58
C# Question

Strange Auto-Date Format Datagrid

I got this XAML for my Datagrid Column:

<DataGridTemplateColumn SortMemberPath="LiefDat" Width="110" x:Name="columnLieferDatum" >
<DataGridTemplateColumn.Header >
<TextBlock Text="Lieferdatum"/>
<Label Width="110" x:Name="lblLiefDat" Content="{Binding LiefDat, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}"/>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=DataGridRow}}"
<Setter TargetName="lblLiefDat" Property="Foreground" Value="white" />

I read out the data from a XML which got this field in a format like: 2001-02-16T00:00:00+01:00

The Datagrid auto converts this value into: 2.16.2001, how i change this to 16.2.2001, already tried this


With the tip of @Dominic Jonas i got the solution:

Content="{Binding LiefDat}" ContentStringFormat="dd.MM.yyyy"

Adding it like this in the XAML was the right way

Answer Source

If you set

StringFormat=\{0:dd.MM.yy HH:mm:ss\}

then a hard coded string format is given. Try it with:


Then the format is dynamicly generated. Here is a small list with examples: http://www.csharp-examples.net/string-format-datetime/

But that requires you to use a global language setting (like you already did).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download