0

In my application I bind labels, textblocks etc. to double values in the view model.

<Label Content="{Binding DoubleValue}" ContentStringFormat="{}{0:0.00}">
<TextBlock Text="{Binding DoubleValue, StringFormat='\{0:f2\}'}"

In my "code behind" I set the language property of the MainWindow:

TheMainWindow.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.Name);

This works like a charm. When german culture is selected, all double values use the comma as decimal symbol and when english culture is selected, all double values use the point as decimal symbol.

The problem is when you customize the windows region settings, e.g. I configure the german reagion setting to have a point as decimal separator.

The StringFormat method does not recognize this custom setting! It still formats the double values with a comma as decimal symbol.

If I create a string property in the view model like this

public string FormattedDoubleValue
{
        get { return DoubleValue.ToString("0.00"); }
}

and bind to this property, this does recognize the custom region setting!

Is there any way to make the StringFormat method recognize the custom region settings?

PainElemental
  • 687
  • 6
  • 14

1 Answers1

0

I found a solution here: CurrentUICulture ignores Region and Language settings

Using the answer of MSkuta works without having to change all my xaml files :)

PainElemental
  • 687
  • 6
  • 14