I have a Silverlight 4 application. I have a C# DateTime object that I'm binding to my UI. I want this DateTime to be in the format of dd/mm/yyyy
time (TimeZone). For instance, today would be displayed as
04/07/2011 at 01:13 p.m. (EST)
Is there a way to do this XAML
? Or do I need to build a converter?
<TextBlock Text="{Binding Date, StringFormat='{}{0:MM/dd/yyyy a\\t h:mm tt}'}" />
will return you
04/07/2011 at 1:28 PM (-04)
I love these F~€#~€ weird string formats ... who the hell can recall them (talking about the {}0: part).
This is correct, except your quotes around the format string should be single quotes <TextBlock Text="{Binding Date, StringFormat={}{0:'MM/dd/yyyy a\\t h:mm tt'}}" />
I had to put my single quotes in a different place: Text="{Binding startDate, StringFormat='{}{0:MM/dd/yy}'}"
If you're using a
Label
rather thanTextBlock
, recall that you need to useContentStringFormat
instead of setting the Binding StringFormat.all these work for a textblock or textbox but inside a datepicker itself the formats does not work. Any idea how to do it in the date picker