I have a TextBlock with a long line of text which I want to wrap. I've placed the TextBlock within a ViewBox expecting the text size to change while still wrapping, however this doesn't seem to happen. The ViewBox just resizes the TextBox so that all the text fits on one line making the text really small.
How can I use the ViewBox to resize the text while still using TextWrapping.
Here is my code:
<Viewbox>
<TextBlock Text="The Option text can also dynamically grow/shrink to fit more content. More text to go here....................." TextWrapping="Wrap"/>
</Viewbox>
This is part of a Windows 8 store application so is WinRT Xaml.
Just set a width on the
TextBlock
.So the
ViewBox
will zoom in/out its entire contents. If you don't restrict its contents by either setting a width on theTextBlock
, theViewBox
will give it infinite space to expand into. You can also add a rootGrid
with a width and height within theViewBox
and lay your elements out in that, then the whole lot will get zoomed according to the width of theViewBox
.In the image, the width of the
TextBlock
100 is zoomed to be the width of theViewBox
which is 500. So to get the wrapping you want, just tweak theTextBlock
width until it looks nice.(Obviously it should say three lines but I'm not re-uploading just for that)