[英]Binding in windows phone 8
Can you explain how can i put binding element and plain text at the same time in a textblock? 您能解释一下如何将绑定元素和纯文本同时放入文本块吗?
Text="{Binding following} Following | {Binding follower} Followers"
other side 另一边
followte.Text = rootObject.following;
followert.Text = rootObject.follower;
Windows Phone doesn't support multi-binding, so you need to use multiple <Run>
s to bind TextBlock
's Text
to multiple model properties. Windows Phone不支持多重绑定,因此您需要使用多个<Run>
来将TextBlock
的Text
绑定到多个模型属性。 And you need to set StringFormat
as well to display the plain-text part : 并且您还需要设置StringFormat
来显示纯文本部分:
<TextBlock>
<Run>
<Run.Text>
<Binding Path="following" StringFormat="{}{0} Following"/>
</Run.Text>
</Run>
<Run>
<Run.Text>
<Binding Path="follower" StringFormat="{} | {0} Followers"/>
</Run.Text>
</Run>
</TextBlock>
Don't set Text
property manually when you're using DataBinding
. 使用DataBinding
时不要手动设置Text
属性。 That will override the bound value. 这将覆盖绑定值。 Set the DataContext
instead : 改为设置DataContext
:
myTextBlock.DataContext = rootObject;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.