Search code examples
c#wpftextblock

I'm using a WPF TextBlock but then text gets cut off when it's too long. Is there an AutoScroll feature?


My TextBlock has for example 50x50 pixels to display text, however if there is more text, I want a user to be able to scroll. Is there an autoscroll feature for this control?

Should I use a different control better suited for this task?

Here's a couple of pics to illustrate the problem:

This one works fine because the text fits in snugly: alt text

This one doesn't seem correct. Text is cut off. alt text


Solution

  • Just in case someone comes into the same problem. Just wrap the textBlock with a control. Works like a charm!

    <ScrollViewer Background="Black">
        <TextBlock x:Name="textBlockBackStory" 
                   FontSize="12" 
                   Foreground="Orange" 
                   TextWrapping="Wrap"                       
                   Background="Black" 
                   TextDecorations="None">
                                Backstory here.
        </TextBlock>      
    </ScrollViewer>