开发者

How to get text fit in text block in WPF

开发者 https://www.devze.com 2022-12-13 04:53 出处:网络
I have string which i have to display in TextBlock, my TextBlock have some fixed size, i needdisplay the text in such manner i开发者_如何学编程f string cannot fit in TextBlock, then i have to split th

I have string which i have to display in TextBlock, my TextBlock have some fixed size, i need display the text in such manner i开发者_如何学编程f string cannot fit in TextBlock, then i have to split the string in next TextBlock, how can i do this same.


Why don't you try using the TextWrapping property of that TextBlock?

XAML:

<TextBlock TextWrapping="Wrap" Text="very very very long text" Width="30"/>

C#:

myTextBlock.TextWrapping = TextWrapping.Wrap;


If you don't want wrapping, then slapping on a horizontal/vertical scrollbar is another option that you may want to explore. Reading the question I think textwrapping might be more appropriate (doesn't sound like you want to hide anything), but options are always nice.

<ScrollViewer Height="30">
    <TextBlock Width="30" TextWrapping="Wrap">HElooooooooooooooooooooooooooooooooooooo</TextBlock>
</ScrollViewer>

EDIT: Combines a word wrap and a scrollviewer.

0

精彩评论

暂无评论...
验证码 换一张
取 消