Search code examples
c#silverlightwindows-phone-7datetimesilverlight-toolkit

How to set a common date format across the entire Application - Silverlight/Windows Phone 7


I am using datetime displayed in a lot of places in my Windows Phone 7 Application. The default date format looks ugly and I formatted it to something like this.

<TextBlock Text="{Binding Date, StringFormat='MMM d, h:mm tt'}"/>

The obvious problem with the above code is that I will have to do this copy pasting like everywhere. So, if a date format changes at some place, then I will have to do the same redundantly everywhere. Is there a better way to handle this in Silverlight/C# ?

Even better, is there a way to override Date.ToString() for the entire Application so that I can do the formatting there and I can simply have my code like this (I ask this because I do Ruby and in Ruby this is possible)

<TextBlock Text="{Binding Date}"/>

If both are not possible, please guide me in solving this problem.


Solution

  • A ValueConverter may be?

    1. http://forums.silverlight.net/t/12617.aspx
    2. http://timheuer.com/blog/archive/2008/07/30/format-data-in-silverlight-databinding-valueconverter.aspx