user818700
user818700

Reputation:

Windows Phone TextBlock Auto Resize

I have a TextBlock in my Windows Phone app, the Text value of that TextBlock gets set programatically, so there's no way in knowing how big the string is going to be that fills it. Right now I have a static size for that TextBlock but when the string that fills it goes outside the size of that TextBlock. Then it's not displayed.

Is there a way to auto resize that TextBlock so that when its Text attribute exceeds it's size/width, it resizes?

Thanks in advance!

Upvotes: 0

Views: 3409

Answers (2)

Diana Mikhasyova
Diana Mikhasyova

Reputation: 1660

TextBlock ActualWidth property should return you the runtime width of the text.

So you can try this:

< TextBlock Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"
    Name="tb" Text="{Binding ElementName=txt, Path=Text}"/>

Upvotes: 1

nkchandra
nkchandra

Reputation: 5557

Set the TextWrapping property of the TextBlock to Wrap:

<TextBlock TextWrapping="Wrap"/>

Upvotes: 1

Related Questions