10

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.

Charles
  • 155
  • 8
  • Other things I've tried: setting `xml:lang="en-AU"` on the parent Window, setting `ConverterCulture=en-AU` on the Binding. Neither worked... (there isn't a converter on the Binding, but I figured I'd try it anyway) – Charles Nov 05 '12 at 00:08
  • 2
    `DateTime.Parse("1/11", CultureInfo.GetCultureInfo("en-AU")).Month` gives 11 on Windows 7, but 1 on Windows 8 - this isn't a WPF bug any more... – Charles Nov 05 '12 at 01:11
  • 1
    On Windows 8: en-AU gives 1, en-GB gives 11, en-US gives 1, fr gives 11 – Charles Nov 05 '12 at 23:19
  • How about a workaround where you use a ValueConverter instead. Is this a OneWay or TwoWay binding? – user1834059 Nov 24 '12 at 22:44
  • It's TwoWay. (I ended up just changing the LanguageProperty override to use en-GB for the time being, which isn't perfect, but it's pretty good.) – Charles Nov 26 '12 at 09:33
  • 1
    Given what you've found, you may want to adjust the question, and especially the tags. Sounds like us Aussies have a bad registry entry in Win8. – Mark Hurd Jan 05 '13 at 05:45
  • @MarkHurd I'm not sure whether it is a registry setting or not but we have recently had a similar issue on windows server 2012. The above line returns the month as `1`. So its not confined to Win8. – James Khoury Feb 27 '13 at 04:36
  • @JamesKhoury It hasn't affected me yet, but it looks like it should be listed on Connect as a problem then. (May be it is...) – Mark Hurd Feb 27 '13 at 06:16

2 Answers2

1

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.

  • Using `Name` instead of `IetfLanguageTag` makes no difference, they're the same, both on Windows 7 and Windows 8. (As that page says - "IETF tags and names are identical.") – Charles Jan 07 '13 at 07:56
0

Using

System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern = "dd MMMM";

Will update your current thread's Month and Day format. The MonthDayPattern changed in Windows Server 2012. I haven't figured out why yet.

user917170
  • 1,591
  • 15
  • 28