Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change date format in Silverlight DatePicker control?

This works great:

<my:DatePicker IsTodayHighlighted="True" Width="200">
</my:DatePicker> 

But I want to format the date, something like this:

<my:DatePicker IsTodayHighlighted="True" Width="200" Format="yyyy-mm-dd">
</my:DatePicker> 

Anyone know the syntax for this?

like image 695
Edward Tanguay Avatar asked Jan 25 '09 16:01

Edward Tanguay


2 Answers

Unfortunately the DatePicker control currently does not support free DateTime formats.

If this is something you're interested in seeing up support in future version of DatePicker, please create a codeplex feature request that suggests that. http://silverlight.codeplex.com/WorkItem/Create.aspx

Just to point out that the new Silverlight Toolkit March 2009 TimePicker & TimeUpDown controls do support a full range of globalization options. One of those include free DateTime formats. So it is just a matter of public interest on whether or not we port that ability back to DatePicker. Have a look at the format for TimePicker @ http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201#TimePicker

In the meanwhile, The best workaround is to either change the local culture or the format on the local culture.

    public App()
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL");

or change the format on the local culture.

        public App()
    {
        Thread.CurrentThread.CurrentCulture = (CultureInfo) Thread.CurrentThread.CurrentCulture.Clone();
        Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "D/m/yyyy";
like image 118
JustinAngel Avatar answered Oct 21 '22 22:10

JustinAngel


You should define a custom control template and edit the textbox of the datepicker control to format the text.

like image 21
Deep1 Avatar answered Oct 21 '22 22:10

Deep1