Silverlight TextBlock 文本属性与内容
何时使用
的 Text 属性以及何时应将文本放入
的内容中?
<TextBlock Text="Example Text" />
vs.
<TextBlock>Example Text</TextBlock>
When would I use the Text attribute of the <TextBlock>
and when should I put my text in the content of the <TextBlock>
?
<TextBlock Text="Example Text" />
vs.
<TextBlock>Example Text</TextBlock>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前者可以绑定,而后者在组合
Run
时特别有用:The former can be bound, whilst the latter is particularly useful when combining
Run
s:由于以前版本的 Xaml 解析器,
Text
属性的使用变得很常见,但将文本作为内容放置更为自然,特别是如果您有 HTML 背景的话。事实上,许多 TextBlock 要么包含简单的短文本块,要么被绑定。在我看来,将使用
Text
属性来平衡。此外,后者可能出现的任何全球化也可能以这些文字也被绑定所取代而结束。The use of the
Text
property has become common as a result of previous versions of the Xaml parser but the placing the text as content is more natural especially if you have a background in HTML.The fact the many TextBlocks either have simple short chunks of literal text in or are bound. Would tip the balance IMO to using the
Text
property. In addition any globalisation that may come along latter may end with those literals being replaced by bindings as well.