Reputation: 5673
WPF controls don't seem to have a .Culture
property, or any other obvious way of controlling how text is localised. Worse, on my test machine it doesn't even respect the system locale. My application needs to work for Germans, so the test machine runs a German version of windows and C# respects this. Thus
String.Format('{0}', 3.5) == "3,5"
But if I leave the localisation to WPF, e.g. by binding a numeric property directly to a label or a datagrid cell, I see some kind of American formatting. So if I format 3.5
as currency then I would see $3.50
on-screen.
So:
Ideally "fix" means making it respect the system locale by default, while giving me explict control over particular things. Thus if I have a German invoice opened on an Australian PC, the ideal thing would be for a price to look like €3.50
.
Upvotes: 0
Views: 948
Reputation: 273199
WPF does indeed default to US, regardless of the System setings.
You can do an application-wide setting in App.Xaml.cs :
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// Thread settings are separate and optional
// affect Parse and ToString:
// Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
// affect resource loading:
// Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(
CultureInfo.CurrentCulture.IetfLanguageTag)));
base.OnStartup(e);
}
Upvotes: 3