patterncsharpCritical
Automatic vertical scroll bar in WPF TextBlock?
Viewed 0 times
wpfverticalbarscrollautomatictextblock
Problem
I have a
How can I make vertical scroll bar created automatically for my
Clarification: I would rather do it from the designer and not by directly writing to the XAML.
TextBlock in WPF. I write many lines to it, far exceeding its vertical height. I expected a vertical scroll bar to appear automatically when that happens, but it didn't. I tried to look for a scroll bar property in the Properties pane, but could not find one.How can I make vertical scroll bar created automatically for my
TextBlock once its contents exceed its height?Clarification: I would rather do it from the designer and not by directly writing to the XAML.
Solution
Wrap it in a scroll viewer:
NOTE this answer applies to a
If you want to show scroll bars in a
Valid values for these two properties are
NOTE this answer applies to a
TextBlock (a read-only text element) as asked for in the original question.If you want to show scroll bars in a
TextBox (an editable text element) then use the ScrollViewer attached properties:Valid values for these two properties are
Disabled, Auto, Hidden and Visible.Code Snippets
<ScrollViewer>
<TextBlock />
</ScrollViewer><TextBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto" />Context
Stack Overflow Q#1192335, score: 654
Revisions (0)
No revisions yet.