I am trying to change the number formatting in my WPF application. I want international standardized formatting (space as thousand separator), and also "--" as NaN symbol.
I clone a CultureInfo and set the NumberFormatInfo, then set that as Thread.CurrentThread.CurrentCulture in the constructor of the main window (I also tried in WindowLoaded). I also set CultureInfo.DefaultThreadCurrentCulture, and *CurrentUICulture for good measure.
But nothing works. The number formatting in Labels stays as default US format (comma as thousand separator). Why does the app not respond to my setting the culture?
Here is the full code, although I've tried many variations of it so I suspect the actual code is not the problem, but that I am misunderstanding something about how cultures work:
CultureInfo myNumberCulture = (CultureInfo)CultureInfo.InvariantCulture.Clone();
myNumberCulture.NumberFormat = new NumberFormatInfo
{
NaNSymbol = "--",
NumberGroupSeparator = " ",
PercentGroupSeparator = " ",
CurrencyGroupSeparator = " ",
NumberDecimalSeparator = ".",
PercentDecimalSeparator = ".",
CurrencyDecimalSeparator = "."
};
Thread.CurrentThread.CurrentCulture = myNumberCulture;
CultureInfo.DefaultThreadCurrentCulture = myNumberCulture;