NumberFormatInfo.CurrentInfo.CurrencySymbol 未被识别为 XAML 中的静态属性
我正在编写一个 WPF 应用程序,我想在表单上显示所选区域性的货币符号。
所以我添加了这个文本块
<TextBlock Text="{x:Static globalization:NumberFormatInfo.CurrentInfo.CurrencySymbol}" Style="{StaticResource TextStyle}" VerticalAlignment="Center"/>
编译器抱怨它找不到 NumberFormatInfo.CurrentInfo 尽管这是公共类中的静态属性。 以相同的形式,我能够从同一命名空间成功引用CultureInfo.CurrentCulture。这证实了我的命名空间声明没有任何错误。
我的解决方法是为文本块提供 x:Name,然后从后面的代码分配其文本,但我想以正确的方式执行此操作。
谢谢, 法迪
I'm writing a WPF application in which i want to display the currency symbol of the selected culture on the form.
So i have added this text block
<TextBlock Text="{x:Static globalization:NumberFormatInfo.CurrentInfo.CurrencySymbol}" Style="{StaticResource TextStyle}" VerticalAlignment="Center"/>
The compiler is complaining that it cannot find NumberFormatInfo.CurrentInfo although this is a static property in a public class.
In the same form i'm able to successfully refer to CultureInfo.CurrentCulture from the same namespace. This confirms that i have nothing wrong in my namespace declaration.
My workaround is to provide an x:Name to the textblock and then assign its text from the code behind, but i want to do it the right way.
Thanks,
Fadi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仔细阅读错误信息,它说明了问题所在:
它正在查找 type
NumberFormatInfo.CurrentInfo
的属性CurrencySymbol
,但该属性不存在。要绑定到该属性,您可以使用CurrentInfo
作为Binding
的源:Read the error message carefully, it says where the problem is:
It's looking for the property
CurrencySymbol
of the typeNumberFormatInfo.CurrentInfo
, which doesn't exist. To bind to that property, you can use theCurrentInfo
as a source forBinding
: