TextBlock text doesn't wrap when placed inside a ViewBox

Sun

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.

Luke Puplett

Just set a width on the TextBlock.

        <Viewbox Width="500">
            <TextBlock Width="100" TextWrapping="Wrap">This is the text that's long and on two lines.</TextBlock>
        </Viewbox>

TextBlock with width 100 in ViewBox with width 500

So the ViewBox will zoom in/out its entire contents. If you don't restrict its contents by either setting a width on the TextBlock, the ViewBox will give it infinite space to expand into. You can also add a root Grid with a width and height within the ViewBox and lay your elements out in that, then the whole lot will get zoomed according to the width of the ViewBox.

In the image, the width of the TextBlock 100 is zoomed to be the width of the ViewBox which is 500. So to get the wrapping you want, just tweak the TextBlock width until it looks nice.

(Obviously it should say three lines but I'm not re-uploading just for that)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Text in a flex container doesn't wrap in IE11

From Dev

TextBlock doesn't show Text even after Binding

From Dev

when using UIWebview and dropdown, ios7 picker doesn't wrap the text.

From Dev

pandoc doesn't text-wrap code blocks when converting to pdf

From Dev

Make a Part of Text Bold inside TextBlock

From Dev

Why doesn't TextBlock bind?

From Dev

Cannot get TextBlock to word wrap inside a ListBox

From Dev

PDF doesn't wrap text lines automatically & respect line position

From Dev

TextView inside TableLayout and TableRow doesn't wrap text

From Dev

How to wrap text in textblock?

From Dev

CSS Text doesn't wrap?

From Dev

Convert Enum to string inside TextBlock text

From Dev

<a> doesn't wrap span, and appears as text

From Dev

Access TextBlock.Text Inside a Button

From Dev

WPF XAML ListView - Make TextBlock Text wrap

From Dev

Text doesn't wrap, breaks layout instead

From Dev

TextBlock doesn't show Text even after Binding

From Dev

CSS div with full width but doesn't wrap text

From Dev

How to wrap text in textblock?

From Dev

Binding TextBlock Text to Window Title doesn't work

From Dev

TextBlock doesn't update content

From Dev

Text doesn't wrap in IE 11 flex layout

From Dev

WPF - how to go to new TextBlock line inside wrap panel?

From Dev

Text doesn't wrap in evenly distributed, even width flexbox

From Dev

Why Frame does not find local resource when it's placed inside a ViewBox?

From Dev

How to wrap text around an image placed at the END of a block of text?

From Dev

TextBlock in ListViewItem won't wrap

From Dev

Subview (UILabel) doesn't respect the constraints when placed in superview (UITextView)

From Dev

Paragraph text doesn't wrap around to next line

Related Related

HotTag

Archive