简体   繁体   English

负货币号XAML

[英]Negative currency number XAML

I have a little problem with the current format of my negative currency number. 我的负货币编号的当前格式有点问题。 Here's a screenshot resuming my situation. 这是一个截图,恢复了我的情况。

  1. This is how I'm using the StringFormat in my binding. 这就是我在绑定中使用StringFormat的方式。 (BTW, I tried only {0:C}) (顺便说一下,我只试过{0:C})
  2. As expected 正如所料
  3. The current settings of my computer for the negative currency number 4. 我的计算机的当前设置为负数货币4。
  4. The result when I'm running my application 我正在运行我的应用程序时的结果

替代文字

Why the result isn't -0,08 $ ? 为什么结果不是-0,08 $?

Any ideas of how I should proceed? 关于我应该如何进行的任何想法?

Thanks for your time. 谢谢你的时间。

UPDATE: 更新:

I tried to resolve the problem with a converter, here's the result : 我尝试用转换器解决问题,结果如下:

  • I found that the Thread.CurrentThread.CurrentUICulture was not the same as the Thread.CurrentThread.CurrentCulture , so I fixed it in my App.xaml.cs. 我发现Thread.CurrentThread.CurrentUICultureThread.CurrentThread.CurrentCulture ,所以我在App.xaml.cs中修复了它。 Unfortunately, same result. 不幸的是,结果相同。
  • I tried to display my values through a converter to see if I could debug the problem. 我试图通过转换器显示我的值,看看我是否可以调试问题。 The fact is that the culture received in the parameters of the Convert method was okay, but its CurrentNegativePattern was not the same as in the Thread.CurrentThread.CurrentCulture . 事实是,在Convert方法的参数中收到的文化是可以的,但它的CurrentNegativePatternThread.CurrentThread.CurrentCulture中的不一样。 That's probably the reason why I have this problem. 这可能就是我遇到这个问题的原因。 for the moment, I'll use this : return ((double)value).ToString("C2", Thread.CurrentThread.CurrentCulture); 目前,我将使用这个: return ((double)value).ToString("C2", Thread.CurrentThread.CurrentCulture); in the Convert method of my converter. 在我的转换器的Convert方法中。

Try changing the CurrentCulture to CurrentUICulture : 尝试将CurrentCulture更改为CurrentUICulture

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

Please note though that this may not use your regional settings. 请注意,这可能不会使用您的区域设置。 The CultureInfo object does describe your regional settings, but what you're doing with the IetfLanguageTag is extracting that to a specific culture. CultureInfo对象确实描述了您的区域设置,但您对IetfLanguageTag是将其提取到特定文化。 That culture does not have the adjustments you've made to your regional settings. 该文化没有您对区域设置所做的调整。

Alternatively, you can have a look at the ConvertCulture option of the binding. 或者,您可以查看绑定的ConvertCulture选项。 This actually does take a CultureInfo . 这确实需要一个CultureInfo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM