0

Upon updating my WPF application to net5 I noticed that StringFormat set on a TextBlock seems to use different culture settings than calling ToString from code. Specifically CurrencyNegativePattern is different.

<TextBlock Text="{Binding Value, StringFormat=C0}"/>

with Value=-10 Will format like -$10

While

(-10).ToString("C0")

will format like ($10)

This app demonstrates the issue: https://github.com/innominate227/WpfCurrencyNegativePatternIssue

Is there anyway to get WPF to use the same format that is used by the ToString()?

innominate227
  • 11,109
  • 1
  • 17
  • 20
  • Does this help? https://stackoverflow.com/a/520334/3390788 – Frank Alvaro Nov 21 '22 at 23:03
  • @FrankAlvaro No, I can set the WPF Language property to "en-US", but that still acts differently than new CultureInfo("en-US"). – innominate227 Nov 21 '22 at 23:48
  • Further traced this to changes in behavior of XmlLanguage.GetEquivalentCulture starting with net5.0. Filled a bug report here: https://github.com/dotnet/wpf/issues/7307 – innominate227 Nov 22 '22 at 00:41
  • `(-10).ToString("C0", new CultureInfo("en-US"))` returns "-$10", doesn't it? – mm8 Nov 23 '22 at 10:38
  • Returns "($10)" for me. https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYAMBYAUBgRjz1QIE4AKCgWgMwEoA6AFQHsBlYMASygHMKAIgDCmQTAAEUAKYB3CaUYBxADasARgEMV3AF6bg3VlEbCIK4BDDSAklABmrIdKjUAqu0H1vAbiA== – innominate227 Nov 23 '22 at 17:41

0 Answers0