Skip to content

DateTimePicker sets the Culture to InvariantCulture and breaks any other globalization in the app #1065

@jhm-ciberman

Description

@jhm-ciberman

Describe the bug
DateTimePicker sets the culture to InvariantCulture and breaks any other globalization in the app.

See screenshots below for details.

The problem is caused by this PR:
#679

This pr adds this line to the constructor of DateTimePicker:

Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

To Reproduce
Steps to reproduce the behavior:

  1. Set the globalization to something other than Invariant culture. For example, this is the code I use in my app to setup the Culture at the start of the application:
// Spanish Argentinian culture. The currency sign is the PESOS $ symbol (same as dollars symbol)
CultureInfo culture = (CultureInfo)CultureInfo.GetCultureInfo("es-AR").Clone(); 
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;

// Override culture for any thread that will be created after
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

// Override culture for XAML Views
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

2 - Then add any thing that requires globalization in the UI thread. For example, using System.Globalization inside XAML:

<!-- xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib" -->

<TextBlock Text="{Binding Amount, StringFormat='C', ConverterCulture={x:Static sysglb:CultureInfo.CurrentCulture}}"/>

3 - Then use the DateTimePicker anywhere on your app

<hc:DateTimePicker
    SelectedDateTime="{Binding DateTime, UpdateSourceTrigger=PropertyChanged}"/>

4 - After using the component and reloading the screen, the money format should be showing with the Global currency sign like this ¤ 1234 (https://en.wikipedia.org/wiki/Currency_sign_(typography))

Expected behavior
The component should not have this side effect

Screenshots
Before opening any screen that uses the DateTimePicker in my app, the culture of the app looks correct:

image

When I use the component in my app, all looks okay:

image

After using the component, the culture is set to invariant culture. All the money format is displayed incorrectly:

image

Environment (please complete the following information):

  • .net: Net 5
  • IDE VS2019
  • Version: HandyControls v3.3.7

Metadata

Metadata

Assignees

Labels

🐛 bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions