-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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:
- 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:
When I use the component in my app, all looks okay:
After using the component, the culture is set to invariant culture. All the money format is displayed incorrectly:
Environment (please complete the following information):
- .net: Net 5
- IDE VS2019
- Version: HandyControls v3.3.7
Metadata
Metadata
Assignees
Labels
Type
Projects
Status