TextBox.VerticalScrollBarVisibility Property

July 28, 2014

Gets or sets the visibility of the vertical scroll bar.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
<TextBox VerticalScrollBarVisibility="scrollBarVisibilityValue"/>

XAML Values

scrollBarVisibilityValue

A named constant of the ScrollBarVisibility enumeration, such as Auto.

Property Value

Type: System.Windows.Controls.ScrollBarVisibility
The visibility of the vertical scroll bar. The default is Hidden.

If VerticalScrollBarVisibility is Disabled, the text box does not scroll vertically.

The following code snippets show how you can use the VerticalScrollBarVisibility property in XAML and code.


<StackPanel>
    <TextBox Margin="20,20,0,0" Text="A text box that demonstrates TextWrapping, TextAlignment, MaxLength, and AcceptsReturn" 
             Width="300" Height="150" TextWrapping="Wrap" TextAlignment="Center" MaxLength="500" AcceptsReturn="True" />
    <TextBox Margin="20,20,0,0" Text="A text box that demonstrates HorizontalScrollBarVisibility and VerticalScrollBarVisibility" 
             Width="300" Height="150" AcceptsReturn="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" />
</StackPanel>



public Page()
{
    InitializeComponent();
    CreateControls();
}

private void CreateControls()
{
    //Create stack panel
    StackPanel MyStackPanel = new StackPanel();

    //Create the first text box
    TextBox MyTB1 = new TextBox();
    MyTB1.Width = 300;
    MyTB1.Height = 150;
    MyTB1.Text = "A text box that demonstrates TextWrapping, TextAlignment, MaxLength and AcceptsReturn";
    MyTB1.TextWrapping = TextWrapping.Wrap;
    MyTB1.TextAlignment = TextAlignment.Center;
    MyTB1.MaxLength = 500;
    MyTB1.AcceptsReturn = true;
    MyTB1.Margin = new Thickness(20, 20, 0, 0);

    //Create the second text box
    TextBox MyTB2 = new TextBox();
    MyTB2.Margin = new Thickness(20, 20, 0, 0);
    MyTB2.Text = "A text box that demonstrates HorizontalScrollBarVisibility and VerticalScrollBarVisibility";
    MyTB2.Width = 300;
    MyTB2.Height = 150;
    MyTB2.AcceptsReturn = true;
    MyTB2.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
    MyTB2.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;

    //Add the text boxes to the stack panel
    MyStackPanel.Children.Add(MyTB1);
    MyStackPanel.Children.Add(MyTB2);
    this.Content = MyStackPanel;
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft