开发者

NumberFormatInfo.CurrentInfo.CurrencySymbol is not being recognized as a static property in XAML

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 s开发者_JAVA技巧ame 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


Read the error message carefully, it says where the problem is:

Cannot find the type 'NumberFormatInfo.CurrentInfo'.

It's looking for the property CurrencySymbol of the type NumberFormatInfo.CurrentInfo, which doesn't exist. To bind to that property, you can use the CurrentInfo as a source for Binding:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜