当放置在ViewBox中时,TextBlock文本不会自动换行 [英] TextBlock text doesn't wrap when placed inside a ViewBox

查看:157
本文介绍了当放置在ViewBox中时,TextBlock文本不会自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextBlock,其中包含要包装的一长行文本.我将TextBlock放置在ViewBox中,期望文本大小在仍换行时发生变化,但是这似乎没有发生. ViewBox只是调整TextBox的大小,以便所有文本都适合一行,从而使文本很小.

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.

如何在仍然使用TextWrapping的同时使用ViewBox调整文本大小.

How can I use the ViewBox to resize the text while still using TextWrapping.

这是我的代码:

<Viewbox>
    <TextBlock Text="The Option text can also dynamically grow/shrink to fit more content. More text to go here....................." TextWrapping="Wrap"/>
</Viewbox>

这是Windows 8应用商店应用程序的一部分,WinRT Xaml也是如此.

This is part of a Windows 8 store application so is WinRT Xaml.

推荐答案

只需在TextBlock上设置宽度.

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

因此,ViewBox将放大/缩小其全部内容.如果您不通过在TextBlock上设置宽度来限制其内容,则ViewBox将为其提供无限的空间来扩展.您还可以在ViewBox内添加一个宽度和高度为根的Grid根,并在其中放置元素,然后根据ViewBox的宽度对整个批次进行缩放.

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.

在图像中,将TextBlock 100的宽度缩放为ViewBox的宽度,即500.因此,要获得所需的包装,只需调整TextBlock的宽度,直到看起来不错为止.

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)

这篇关于当放置在ViewBox中时,TextBlock文本不会自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆