Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Datepicker ignores culture
2 replies. Latest Post by Lexxy on October 14, 2009.
(0)
Lexxy
Member
0 points
4 Posts
10-08-2009 5:16 AM |
Hello,
I have a Silverlight Datepicker which accepts input in the format DD/MM/YYYY (en-GB). This works normally. However, when a user inputs a short date, DD/MM, the control apparently ignores its culture and converts the value to MM/DD.
I was wondering if there was a solution to this problem without having to manually fix the Datepicker source code.
Cheers.
Amanda W...
All-Star
17241 points
1,466 Posts
10-14-2009 3:10 AM |
Hi,
Lexxy:I have a Silverlight Datepicker which accepts input in the format DD/MM/YYYY (en-GB). This works normally. However, when a user inputs a short date, DD/MM, the control apparently ignores its culture and converts the value to MM/DD.
How did you formate your date format?
We did have a test in our labs, but did not reproduce your problem.
We format the datetime in the silveright's app.xaml.cs file, like below:
private void Application_Startup(object sender, StartupEventArgs e) {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; this.RootVisual = new MainPage(); } }
It works fine, it doese not convert the value into MM/DD, when your input DD/MM.
10-14-2009 4:39 AM |
Hello Amanda,
Thank you for your advice. Unfortunately adding the lines:
Amanda Wang - MSFT:Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
To my application startup did not fix this issue. I also tried setting CurrentUICulture.
The datepicker watermark when there is no text entered is:
<dd/MM/yyyy>
If I enter: 01/05/2009 the picker output is 01/05/2009. Correct.
If I enter 01/22/2009 the picker rejects my input, and resets to last value. Correct.
If I enter 22/05/2009 the picker output is 22/05/2009. Correct.
If i enter: 01/05 the picker output is 05/01/2009. Wrong.
If i enter 22/01 the picker rejects my input, and resets to last value. Wrong.
This problem makes this control totally unsuitable for my LOB application. Any further ideas why this might be happening?
---
System.Windows.Controls v2.0.50727
System.Windows.Controls.Input.Toolkit v2.0.50727
Oh, I should also mention I tested the control on the Silverlight Codeplex Toolkit site. It suffers from the same problem.
-Lexxy.