[英]Binding in windows phone 8
您能解釋一下如何將綁定元素和純文本同時放入文本塊嗎?
Text="{Binding following} Following | {Binding follower} Followers"
另一邊
followte.Text = rootObject.following;
followert.Text = rootObject.follower;
Windows Phone不支持多重綁定,因此您需要使用多個<Run>
來將TextBlock
的Text
綁定到多個模型屬性。 並且您還需要設置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>
使用DataBinding
時不要手動設置Text
屬性。 這將覆蓋綁定值。 改為設置DataContext
:
myTextBlock.DataContext = rootObject;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.