Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entering date in d/mm format in TextBox

I've got a TextBox bound to a nullable DateTime property.

I'm in Australia, so I want dates presented in the d/mm/yyyy format.

On my Windows 7 box, I can enter the date in d/mm format, and it's converted correctly (eg. 1/11 converts to November 1st, 13/1 converts to January 13th etc.)

On my Windows 8 box, the same input is interpreted as if it was in the US format, so 1/11 converts to January 11th, and 13/1 fails (since there is no 13th month).

Both computers are set to use the Australian formats, and I have this code in the Application.StartUp event:

FrameworkElement.LanguageProperty.OverrideMetadata(GetType(FrameworkElement), New FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)))

The Binding's StringFormat is set to d/MM/yyyy, and I've checked that this is correct by also binding a TextBlock to the same property that has its StringFormat set to D (the long date format, which gives values like 'Wednesday, 11 January, 2012').

Does anyone have any ideas?

Update: Further investigation (see comments below) reveals this seems to be an issue with the en-AU culture being different on Windows 8 compared to Windows 7, which means that it interprets dates like '1/11' in mm/dd format on Windows 8, whereas on Windows 7, it interprets them in dd/mm format, which is what I'd expect when using the en-AU culture.

like image 974
Charles Avatar asked Nov 04 '12 00:11

Charles


1 Answers

Since IetfLanguageTag is deprecated, have you considered using the Name property instead?

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.ietflanguagetag.aspx:

The format of an IETF language tag is similar to the culture name returned by the Name property, but does not identify a culture uniquely. That is, different cultures share the same IETF language tag if those cultures have identical linguistic characteristics.

like image 97
user1952413 Avatar answered Oct 25 '22 07:10

user1952413