Silverlight 4 中 TextBlock 的错误或功能?
我在 Silverlight 4 中的 TextBlock 绑定中获得了一些乐趣。
我遇到以下情况:
<TextBlock Text="{Binding Date, StringFormat=g}" />
<TextBlock>
<Run Text="{Binding Date, StringFormat=g}"/>
<TextBlock>
其中 Date
是 System.DateTime
类型的属性。
我没有改变应用程序的当前文化。
我的机器的文化是保加利亚(bg-BG)。 例如:
文本块 1: 11/16/2011 12:49 PM
文本块 2:2011 年 11 月 16 日12:49 小时。
有趣的是,第一个 TextBlock
使用 en-Us 区域性(或默认的不变区域性)来格式化日期和时间,而第二个则使用 bg-BG 区域性。 自从 MSDN 文档< /a> 对于 Silverlight TextBlock 控件来说:
如果 InlineCollection 是从 XAML 创建为 TextBlock 对象元素的内部文本,或者如果它是通过设置 Text 属性创建的,则 InlineCollection 包含包含该文本的单个 Run。。 p>
我是否在这里遗漏了一些东西,或者它可以被视为 Silverlight 4 中的错误?
I have been having some fun with TextBlock bindings in Silverlight 4.
I have the following situation:
<TextBlock Text="{Binding Date, StringFormat=g}" />
<TextBlock>
<Run Text="{Binding Date, StringFormat=g}"/>
<TextBlock>
Where Date
is a property of type System.DateTime
.
I haven't changed the current culture of the application.
The culture of my machine is Bulgaria (bg-BG).
For example:
TextBlock 1: 11/16/2011 12:49 PM
TextBlock 2: 16.11.2011 г. 12:49 ч.
The interesting thing is that the first TextBlock
formats the date and time using en-Us culture (or the default invariant one) while the second one uses bg-BG culture.
Thing get even stranger since MSDN documentation for Silverlight TextBlock control says:
If the InlineCollection is created from XAML as inner text of a TextBlock object element, or if it is created by setting the Text property, the InlineCollection contains a single Run that contains that text.
Am I missing something here or it can be considered bug in Silverlight 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们发现您需要确保控件的
语言
设置正确,才能使其正确遵循语言设置。在我们的例子中,它是针对货币符号的,但我认为同样的问题也发生在日期上。Tim Heuer 有一篇博客文章 题为“Silverlight 中的 StringFormat 和 CurrentCulture” 关于此内容。
解决方案是将以下行添加到视图构造函数中:
这并不能解释为什么它对于
可以正常工作We have found that you need to make sure that the
Language
of the control is set correctly to get it to honour the language settings correctly. In our case it was for currency symbols, but I assume the same problem occurs for dates as well.Tim Heuer has a blog post entitled "StringFormat and CurrentCulture in Silverlight" about this.
The solution is to add the following line to the view constructor:
This doesn't explain why it works correctly for the
<Run>