WPF format DateTime in TextBlock?

Peter picture Peter · Aug 26, 2009 · Viewed 98.3k times · Source

I have a TextBlock that is bound to a DateTime property. How do I configure the format of the date?

Answer

Martin Harris picture Martin Harris · Aug 26, 2009

There is a string format property available when you are declaring the binding:

<TextBox Text="{Binding Path=DateTimeValue, StringFormat=dd-MM-yyyy}" />

(You need to be on .NET 3.5 SP1 for this property to exist)