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>Ex开发者_开发百科ample Text</TextBlock>
The former can be bound, whilst the latter is particularly useful when combining Run
s:
<TextBlock Text="{Binding SomeProperty}"/>
<TextBlock>
<Run>You have </Run>
<Run Text="{Binding Count}"/>
<Run>items.</Run>
</TextBlock>
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.
精彩评论