February 2010 21:38
In my silverlight app I wanted my datepicker controls to always format dates to M/dd/yyyy date format strings regardless of the current users culture setting.
First I change my regional setting to be English(Ireland) and when I run my app, the datepicker will default to that cultures date format off dd/MM/yyyy
but this isn't what I want, I want it to be M/dd/yyyy.
This can easliy be changed by adding some code to your app.xaml file
//force dates to always be M/dd/yyyy regardless of culture
Thread.CurrentThread.CurrentCulture = (CultureInfo) Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "M/dd/yyyy";
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "h:mm tt";
Now when you run your app, even though your regional settings are set to English (Ireland) the datepicker still has the selecteddateformat of M/dd/yyyyy