How to add Scrolling in WPF TextBox

The HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties are used to set horizontal and vertical scroll bars of a TextBox, which is of type ScrollBarVisibility enumeration. The ScrollBarVisibility enumeration has four values – Disabled, Auto, Hidden, and Visible. The following code snippet sets the horizontal and vertical scroll bars visible in a TextBox.

HorizontalScrollBarVisibility="Visible"

VerticalScrollBarVisibility="Auto"

 

The TextWrapping property sets the wrap of no warp text. The following code snippet sets the wrapping text option.

TextWrapping="Wrap"

The TextAlignment property sets the text alignment in a TextBox, which is of type TextAlignment enumeration. A text can be aligned left, center, or right. 

TextAlignment="Right"

The AcceptReturn property sets if the return is accepted in a TextBox or not.   

AcceptsReturn="True"

Listing 7 shows all these properties in a complete sample.

<TextBox Name="TextBox2" Margin="10,10,50,0"

         Width="300" Height="150"

         HorizontalScrollBarVisibility="Visible"

         VerticalScrollBarVisibility="Visible"

         TextWrapping="Wrap"

         TextAlignment="Right"

         MaxLength="500"

         IsReadOnly="False"

         AcceptsReturn="True" >           

</TextBox>

Listing 7