Search code examples
c#wpfwpf-controlstextblock

How to get text fit in text block in WPF


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.


Solution

  • 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;