Silverlight 忽略CurrencyGroupSeparator
Thread.CurrentThread.CurrentCulture = New CultureInfo("sv-SE")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("sv-SE")
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyGroupSeparator = " "
Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyGroupSeparator = " "
我正在尝试这样做:
<TextBlock Text={Binding decimalValue, StringFormat=c2}/>
它正确设置文化并添加“kr”(瑞典货币符号)。但是,不尊重组分隔符设置。即使我将其设置为“-”或其他任何它也不起作用。
大问号?漏洞?
Thread.CurrentThread.CurrentCulture = New CultureInfo("sv-SE")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("sv-SE")
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyGroupSeparator = " "
Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyGroupSeparator = " "
Im trying to do:
<TextBlock Text={Binding decimalValue, StringFormat=c2}/>
It sets the culture properly and adds the "kr" which is the swedish currency symbol. However, doesnt honor the group separator setting. Even if I set it to "-" or whatever it doesnt work.
Big questionmark? Bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否能够解决这个问题,但由于没有人回答,我会的。
对于初学者来说,我不确定您的支持代码是否与表示层在同一线程中运行;可能不是,我相信 Silverlight 创建了自己的视觉线程。换句话说,设置线程范围的
CultureInfo
不会解决您的问题。有(至少)两种方法可以解决此问题:
1. 使用
StringFormat
属性来设置自定义格式。2. 在支持代码中创建动态属性,该属性将为您格式化值。请找到这个不完美的示例:
并且在您的 XAML 代码中,您不需要指定格式,因此您只需这样做:
I am not sure if you were able to work around this problem, but since nobody answered, I will.
For starters, I am not sure if your backing code runs in the same thread as presentation layer; probably not, that is I believe Silverlight creates its own visual thread. In other words setting thread-wide
CultureInfo
will not resolve your problem.There are (at least) two ways to resolve this issue:
1. Play with
StringFormat
attribute to set custom format.2. Create dynamic property in the backing code which will format the value for you. Please find this imperfect example:
And in your XAML code, you do not need specify format, so you would only do this: