Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21966

Horizontal scroll bar doesn't appear on TextBox

I have a Grid which has a TextBox inside a ScrollViewer:

    <Grid DockPanel.Dock="Top">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ScrollViewer>
            <StackPanel Height="271" Width="258">
                <Label FontSize="15" Margin="10"> Suggestions </Label>
                <Expander x:Name="expander" Margin="10" />
            </StackPanel>
        </ScrollViewer>
        <GridSplitter Grid.Column="0" Width="5" />
        <ScrollViewer Grid.Column="1">
            <TextBox x:Name="textBox" AcceptsReturn="True"
                AcceptsTab="True" FontSize="15"
                VerticalScrollBarVisibility="Visible" 
                HorizontalScrollBarVisibility="Visible"
                TextWrapping="WrapWithOverflow" Language="en-US"
                SpellCheck.IsEnabled="True"/>
        </ScrollViewer>
    </Grid>

Even if I set HorizontalScrollBarVisibility to Visible, the horizontal scroll bar is not visible, and when I type some text that goes beyond the TextBox's width, I can't scroll:

enter image description here

Upvotes: 2

Views: 5103

Answers (2)

Andrei Pana
Andrei Pana

Reputation: 4502

Looking at the implementation of the TextBox: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/TextBox.cs#1473

it seems that this is the normal behavior: the horizontal scrollbar is not visible when TextWrapping is WrapWithOverflow.

Based on that, the only possible way to show the horizontal scrollbar of the TextBox is to set the TextWrapping to NoWrap.

A workarount to what (I think that) you want to achieve with the outer ScrollViewer might be:

<ScrollViewer Grid.Column="1" HorizontalScrollBarVisibility="Visible">
    <TextBox x:Name="textBox" AcceptsReturn="True"
        AcceptsTab="True" FontSize="15"
        VerticalScrollBarVisibility="Hidden" 
        HorizontalScrollBarVisibility="Hidden"
        TextWrapping="WrapWithOverflow" Language="en-US"
        SpellCheck.IsEnabled="True"/>
</ScrollViewer>

Upvotes: 5

Tgeo
Tgeo

Reputation: 153

It appears to me that the TextBox element is not being entirely displayed. I'd bet that the scroll bar is there, you just cannot see it without re-sizing your current window or scrolling downwards in the main window.

Upvotes: 0

Related Questions