为什么这条代码行

<TextBlock Text="{Binding Net, StringFormat=c}"/>

当我所有的区域设置都设置为英国时,将结果输出为$ xx.xx。我希望它以£xx.xx的形式输出。有任何想法吗?我尝试了StringFormat的不同变体,包括StringFormat = {} {0:C},但仍然获得相同的结果。

感谢您的查看。

有帮助吗?

解决方案

我不确定这是否已在.NET 4中固定,但是WPF在呈现货币或日期之类的东西时从未选择过当前的文化。我认为这是一个大规模的监督,但值得庆幸的是,很容易纠正。

在您的应用程序类中:

protected override void OnStartup(StartupEventArgs e)
{
    FrameworkElement.LanguageProperty.OverrideMetadata(
        typeof(FrameworkElement),
        new FrameworkPropertyMetadata(
            XmlLanguage.GetLanguage(
            CultureInfo.CurrentCulture.IetfLanguageTag)));
    base.OnStartup(e);
 }

这个出色的帖子 了解更多信息。

其他提示

我在主窗口中做语言=“ en-gb”,例如

<Window x:Class="AllocateWPF.Vouchers"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test" Height="692" Width="1000" Language="en-GB">

什么对我有用:
1)在app.xaml中覆盖()并添加 - System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("et-EE");

2)在XAML @窗口级别定义 - xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"

3)在XAML中 - <TextBox Text="{Binding Path=Price, StringFormat='{}{0:C}', ConverterCulture={x:Static sysglb:CultureInfo.CurrentUICulture}}" />

正确 接任何东西 风俗 区域设置。虽然我正在手动创建 CultunInfo 在第一步中,我确定可以传递其中一种静态类型 - 例如。 system.globalization.cultureinfo.currentculture (不过我还没有测试...)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top