Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a binding's StringFormat didn't use a current culture?

My current culture is ru-RU. I need it to format decimal to currency string.

decimal n = 111.22M;

n.ToString("C") will return "111,22р."

but when I try to use StringFormat field of a binding I get a "$111.22" result

<TextBlock Text={Binding Number, StringFormat=C} />
like image 312
Viacheslav Smityukh Avatar asked Oct 17 '12 00:10

Viacheslav Smityukh


1 Answers

By default, WPF will use English as the culture for binding StringFormat processing, not the thread's current culture.

You can override this by adding the following in the application's startup code:

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
    new FrameworkPropertyMetadata(      XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

For details, see Josh Smith's article on Creating an Internationalized Wizard.

like image 170
Reed Copsey Avatar answered Oct 12 '22 12:10

Reed Copsey