负货币号XAML

发布于 2024-09-30 02:45:31 字数 856 浏览 0 评论 0原文

我的负货币数字的当前格式有一点问题。 这是恢复我的情况的屏幕截图。

  1. 这就是我在绑定中使用 StringFormat 的方式。 (顺便说一句,我只尝试了 {0:C})
  2. 如预期
  3. 我的计算机的当前设置为负货币数字 4.
  4. 运行应用程序时的结果

alt text

为什么结果不是 -0,08 $ ?

我应该如何进行有什么想法吗?

感谢您抽出时间。

更新:

我尝试使用转换器解决问题,结果如下:

  • 我发现Thread.CurrentThread.CurrentUICultureThread不同。 CurrentThread.CurrentCulture,所以我在 App.xaml.cs 中修复了它。不幸的是,同样的结果。
  • 我尝试通过转换器显示我的值,看看是否可以调试问题。事实是,Convert 方法的参数中收到的区域性没问题,但其 CurrentNegativePatternThread.CurrentThread.CurrentCulture< 中的不同。 /代码>。这可能就是我遇到这个问题的原因。目前,我将在以下方法的 Convert 中使用: return ((double)value).ToString("C2", Thread.CurrentThread.CurrentCulture);我的转换器。

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. (BTW, I tried only {0:C})
  2. As expected
  3. The current settings of my computer for the negative currency number
    4.
  4. The result when I'm running my application

alt text

Why the result isn't -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. 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. 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); in the Convert method of my converter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-10-07 02:45:31

尝试将 CurrentCulture 更改为 CurrentUICulture

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

请注意,这可能不会使用您的区域设置。 CultureInfo 对象确实描述了您的区域设置,但您使用 IetfLanguageTag 所做的是将其提取到特定的区域性。该文化没有您对区域设置所做的调整。

或者,您可以查看绑定的 ConvertCulture 选项。这实际上需要一个CultureInfo

Try changing the CurrentCulture to 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. 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. This actually does take a CultureInfo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文