Reputation: 1202
While playing around with formatting a string with a currency value, I noticed a difference in how WPF displays it.
When formatting a decimal
value in XAML
, WPF displays it as 5,99 €
.
<TextBlock Text="{Binding Total, StringFormat={}{0:C}}"/>
return 5.99m;
When I format in code behind, it displays it as € 5,99
.
<TextBlock Text="{Binding TotalString}"/>
return string.Format("{0:C}", 5.99m);
Is this a bug?
I got Windows 10, targeting .NET version is 4.5.2.
Upvotes: 2
Views: 55
Reputation: 128061
When setting the StringFormat
of a Binding, WPF does not use CultureInfo.CurrentCulture
, but just en-US
by default, or the value you specify by setting the element's (or its parent's) Language
property. See this question for more details.
On the other hand, string.Format
does use CultureInfo.CurrentCulture
. And how that exactly behaves with regard to formatting currencies is configurable by the user.
For example the currency pattern is controlled by the registry value HKEY_CURRENT_USER\Control Panel\International\iCurrency
and can be set in the Control Panel (sorry it's German):
So you might just change that setting to achieve the formatting behaviour you get from StringFormat.
Upvotes: 1