Description
- .NET Core Version: 3.0.100
- Windows version: 18985.1.amd64fre.vb_release.190913-1426
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
Applying FrameworkElement.Language
and related Language
properties does not take into account current culture settings. There is no way how to supply a specific instance of CultureInfo to the WPF infrastructure.
Minimal repro:
<Window x:Class="TestWpfBugs.StaticProperties.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
Language="en-GB">
<TextBlock DataContext="{x:Static s:DateTime.Now}" Text="{Binding}" />
</Window>
(this assumes English (United Kingdom) to be used for formatting. Use other cultures accordingly.)
Go to Settings > Time and Language > Region > Change data formats and change Short date format to a non-default option, e.g. yyyy-MM-dd. Run the WPF app.
Actual behavior: Current culture settings not respected, the date is shown as dd/MM/yyyy.
Expected behavior: The date to be in the selected format.
Ultimately, the XmlLanguage
calls new CultureInfo(name, useUserOverride)
when converting the string into culture. The actual behavior passes false
for the useUserOverride
while the expected behavior would mean passing true
instead.
As a result, there isn't any way I am aware of to make the WPF infrastructure use the current culture that user prefers other than annotating all data bindings and template bindings with converters with explicit cultures, which is a considerable performance hit if possible at all.
Clearly changing the current behavior would not only be a compatibility break but also prevent people from using non-overridden cultures, but there might be other solutions, such as (in decreasing number of scenarios it would allow):
- letting developers to override language with an instance
CultureInfo
rather than just a name string, possible with an extra property of typeCultureInfo
that would be used if set (either onXmlLanguage
or FE, otherwise fallback toLanguage
. - introducing new property e.g.
UseLanguageOverride
onXmlLanguage
supporting returning user overridden cultures, possibly but not necessarily with an extra property on FE too. - introducing special XML language strings meaning "current culture" and "current UI culture".
Any thoughts?