【问题标题】:NumberFormatInfo.CurrentInfo.CurrencySymbol is not being recognized as a static property in XAMLNumberFormatInfo.CurrentInfo.CurrencySymbol 在 XAML 中未被识别为静态属性
【发布时间】:2011-10-05 12:41:33
【问题描述】:

我正在编写一个 WPF 应用程序,我想在表单上显示所选文化的货币符号。

所以我添加了这个文本块

<TextBlock Text="{x:Static globalization:NumberFormatInfo.CurrentInfo.CurrencySymbol}" Style="{StaticResource TextStyle}" VerticalAlignment="Center"/>

编译器抱怨它找不到 NumberFormatInfo.CurrentInfo,尽管这是公共类中的静态属性。 以相同的形式,我能够成功地从同一命名空间引用 CultureInfo.CurrentCulture。这证实了我的命名空间声明没有任何问题。

我的解决方法是为文本块提供一个 x:Name,然后从后面的代码中分配其文本,但我想以正确的方式进行。

谢谢, 法迪

【问题讨论】:

    标签: wpf xaml globalization


    【解决方案1】:

    仔细阅读错误信息,它指出了问题所在:

    找不到类型“NumberFormatInfo.CurrentInfo”。

    它正在寻找不存在的类型 NumberFormatInfo.CurrentInfo 的属性CurrencySymbol。要绑定到该属性,您可以使用CurrentInfo 作为Binding 的源:

    Text="{Binding Source={x:Static globalization:NumberFormatInfo.CurrentInfo}, Path=CurrencySymbol}"
    

    【讨论】:

    • 谢谢。经验教训,x:Static 的格式是固定的“namespace:Class.Property”
    猜你喜欢
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 2011-06-09
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多