Text viewing in a delimited space
I need to visualize a text into a delimited space. If I add a simple TextBlock I have a problem: when the text is longer than the available space, it is cropped at the end. I tried to insert the TextBlock inside a Viewbox: this solution works for a text longer than the available space, but increase the si开发者_运维技巧ze of the text when it is shorter.
Is there a way to reduce the size of the text only when it is longer than the available space?Using a Viewbox, set the StretchDirection property to DownOnly
.
This will set the viewbox to only allow it to scale the content to be smaller, and will prevent it from increasing the size of the content.
<Viewbox StretchDirection="DownOnly">
<TextBlock>Some text that will only be made smaller.</TextBlock>
</Viewbox>
You can also set the Stretch property to Uniform
to scaling keeps the correct aspect ratio if you have problems with it scaling vertically when you don't want it to.
精彩评论