Search code examples
windows-phone-7sizetextblock

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!


Solution

  • 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}"/>