简体   繁体   中英

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. And you need to set StringFormat as well to display the plain-text part :

<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 . That will override the bound value. Set the DataContext instead :

myTextBlock.DataContext = rootObject;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM