Question

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;
Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top