Textblock in Viewbox not multiline

柔情痞子 提交于 2021-02-05 07:59:05

问题


I'm having a bit of a trouble with the autosizing of a text. I read somewhere that if I wanted to achieve that, i need to put my textblock in a viewbox. The problem with that is this way the text isn't split into multiple lines. For example "very very very long text" is almost unreadable, but "simpletext" looks just fine.

<Viewbox Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="4" StretchDirection="DownOnly">
     <TextBlock 
         Text="{Binding FieldName}" VerticalAlignment="Center" HorizontalAlignment="Center"
         TextWrapping="Wrap" FontWeight="Bold" FontFamily="Nueva Std" />
</Viewbox>

Thank you in advance!


回答1:


Try to set a width (or max width) on the TextBlock.




回答2:


Add these properties to your textblock TextWrapping="Wrap" - wrapping IsHyphenationEnabled="True" - breaking the word with hyphen




回答3:


In this case, here is another solution: take this class and make your own LimitedViewbox version, which will have some LowerStretchLimit property. I think it should work.



来源:https://stackoverflow.com/questions/35995215/textblock-in-viewbox-not-multiline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!