German culture and formatting of US numbers


I need to set the culture to german while keeping the US number format. Therefore, I'm setting

var culture = new System.Globalization.CultureInfo("de-DE");
var usCulture = new System.Globalization.CultureInfo("en-US");
culture.NumberFormat = usCulture.NumberFormat;
CultureManager.UICulture = culture;

The CultureManager is from Infralution and enables the switching of languages on the fly. I can verify that the NumberFormat is indeed set to US format with e.g. a "." as decimal seperator after above code. Nevertheless, the following expression

<TextBox Text="{Binding MyDoubleVariable, StringFormat={}{0:0.#}}"/>

where MyDoubleVariable = 2.13 is displayed as 2,13. Where's my mistake? How can I retain the US format?

WPF will use the system culture when performing the formatting. Not aware of the framework to which you refer.

Try creating a custom IValueConverter which takes the culture as a parameter.

To your converter you can create a string property for your format string.

Then in your xaml you can create a convertor instance for each format string you want to use - for example you could have one for money and another for numbers. Add the convertor to your binding and pass a culture specifier as a parameter at that time.

Sorry no code, answering on mobile.