How to get text in a text block in WPF

I have a line that I have to display in a TextBlock, my TextBlock has a fixed size, I need to display the text this way, if the line cannot fit in the TextBlock, then I need to break the line in the next TextBlock, how can I do the same .

+4
source share
2 answers

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

XAML:

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

FROM#:

 myTextBlock.TextWrapping = TextWrapping.Wrap; 
+11
source

If you do not want to wrap, then clicking on the horizontal / vertical scroll bar is another option that you might want to explore. Reading the question, I think that textwrapping might be more appropriate (it doesn't seem like you want to hide something), but the options are always nice.

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

EDIT: combines word wrap and scrollviewer.

+3
source

All Articles