【问题标题】:While I've set Windows to French Regional format and comma as a decimal symbol, the UWP CurrencyFormatter still displays a dot虽然我已将 Windows 设置为法语区域格式并将逗号设置为十进制符号,但 UWP CurrencyFormatter 仍显示一个点
【发布时间】:2018-11-30 14:46:38
【问题描述】:

对于 UWP 应用,我编写了以下转换器。

public class CurrencyConverter : IValueConverter
{
    private readonly CurrencyFormatter _userCurrencyFormatter;
    private readonly CultureInfo _userCulture;

    public CurrencyConverter()
    {
        var userCurrency = Windows.System.UserProfile.GlobalizationPreferences.Currencies[0];
        _userCurrencyFormatter = new CurrencyFormatter(userCurrency);
        _userCulture = new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion);
    }

    public object Convert(object value, Type targetType, object parameter, string language) => value == null ? null : _userCurrencyFormatter.Format((double)(decimal)value);

    public object ConvertBack(object value, Type targetType, object parameter, string language) => decimal.TryParse((string)value, NumberStyles.Number, _userCulture, out var result) ? (decimal?)result : null;
}

我的设置是:

  • windows 地区到法国
  • 区域格式为法语
  • 小数点转逗号
  • 键盘布局为法语(法国)

然而,

  • 我的键盘上的数字键盘仍然显示点而不是逗号
  • 转换器用€显示货币,但用点而不是逗号

更新:

  • 十进制在TextBlock 中用一个点显示
  • 但是,当我在TextBox 中输入小数时,我必须使用逗号

这是我设置的一些屏幕截图

更新:

这是我的转换器的屏幕截图,我们看到尽管语言是法语并且 RegionCode 是 FR,DecimalFormatter 显示一个点作为分隔符而不是逗号。

【问题讨论】:

  • 设置中语言屏幕的主要语言是法语吗?
  • 不,是英文。

标签: windows uwp


【解决方案1】:

UWP 应用程序使用“主要”语言作为应用程序显示语言 - 因此,如果您在系统设置中将英语作为第一语言,则该应用程序将使用英语作为 CultureUICulture,因此格式将也匹配英语。

【讨论】:

  • 这可能是答案,我必须检查一下。然而,UWP 忽略区域格式和小数分隔符是不合逻辑的。
  • 特别是知道我必须使用逗号在 TextBox 中输入十进制值。
  • 这很奇怪,我会进一步检查,也许我也错过了一些东西
  • 我正在尝试重新审视这个问题,所以我添加了一个新的屏幕截图。
猜你喜欢
  • 2021-01-13
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 2012-04-05
  • 1970-01-01
  • 2013-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多