Silverlight DatePicker - SelectedDateFormat ignore culture settings

February 2, 2010 at 9:38 PMdsoltesz

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

public App()

        {

            //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";

            InitializeComponent();

        }

 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

Posted in: c# | silverlight

Tags: , , , , ,

Comments (1) -

shabir ahamed
Qatar shabir ahamed says:

Hi Dan,

Thanks for the help. I was looking for a way to change the date format if silverlight date time picker

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading