3

I'm getting some very strange date formatting issues in my Silverlight application. My local culture is set to UK, yet I am consistently seeing US dates popping up all over the place. I can easily hardcode these to UK format in specific loactions using:

<UserControl ... Language="en-GB"...>

But as I'm sure you'd all agree this is a terrible thing to do.

I have tried setting the Lanaguage to en-GB in the main application and this has partial success. I have also tried Justin Angels suggestion (posted here: How to change date format in Silverlight DatePicker control?), again only partial success.

An example of the issue can be seen here:

http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png

The datagrid on the parent page shows UK formatting, whilst the information in the ChildWindow shows US formatting ...grrrr

Anyone have a definitive solution for solving this across a whole application?

Thanks, Mark

Community
  • 1
  • 1
Mark Cooper
  • 6,738
  • 5
  • 54
  • 92

4 Answers4

1

You can data bind Language property of the root visual element. Take a look at my question here:

How to switch UI Culture of data binding on the fly in Silverlight

Community
  • 1
  • 1
Lex Lavnikov
  • 1,239
  • 9
  • 18
0

Can you not use the SelectedDateFormat property of the datepicker? If you want to do this once could you not create your own usercontrol that derives from the original with this value preset, then use your derived control throughout your app?

Kindness,

Dan

Daniel Elliott
  • 22,647
  • 10
  • 64
  • 82
  • I could use SelectedDateFormat on date pickers but I think this would putting hard coded culture across the app. Would expect that this should "just work" directly from the client culture. Also, this doesn't just relate to date pickers. Sometimes this is bound dates displayed in datagrids, or in textblocks. – Mark Cooper Nov 26 '09 at 10:55
0

Shot in the dark, but does changing the browser's Language Preference make a differnence? I.e. in IE Tools-->Internet Options-->Languages.

HTH

Mark

Mark
  • 2,926
  • 3
  • 28
  • 31
0

You can set the date format for your entire application in the application start up event as follows.This will override any regional settings on the users machine

        Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
        Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = dd/MM/yyyy";
Vasudevan Kannan
  • 911
  • 2
  • 7
  • 22