在windows phone 8中绑定
本文关键字:绑定 phone windows | 更新日期: 2023-09-27 17:59:07
您能解释一下如何在文本块中同时放置绑定元素和纯文本吗?
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;