views:

350

answers:

2

I have string which i have to display in TextBlock, my TextBlock have some fixed size, i need display the text in such manner if string cannot fit in TextBlock, then i have to split the string in next TextBlock, how can i do this same.

+2  A: 

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;
Marcel Benthin
my TextBlock have fixed width as well as fixed height, if i use wordwrap then it will work for width but not for height.
Firoz
In that case I'd suggest a textblock that wraps, and has a vertical scrollviewer - a combination of both our answers.
MoominTroll
Is it realy necessary that your TextBlock has a fixed height? Could you post some Code from your UI definition?
Marcel Benthin
+1  A: 

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.

MoominTroll
Nice idea, but if the textblock is small that would look kind of weird.
Marcel Benthin
True, but "width=30" and "height=30" are completely arbitrary values that work with this small example. If the textblock in the UI is genuinely tiny yet has to hold a lot of text, then I'd argue the UI design is at fault.
MoominTroll