Dillinger
Dillinger

Reputation: 1903

ScrollViewer display two scroll

I'm trying to create a simple log visualizer, so I did the following:

<ScrollViewer>
            <TextBox TextWrapping="Wrap" AcceptsReturn="True" Height="240" IsReadOnly="True"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                     ScrollViewer.CanContentScroll="True"
                     />
 </ScrollViewer>

the ScrollViewer is inside a GroupBox, I can manage it correctly behind the code, but the problem's that I've this UI result:

enter image description here

Howyou can see I've an internal scroller (that working) and an external scroller, that is the ScrollViewer.

This is very strange, wpf doesn't take only one scroller automatically? How can I hide the external scroller, or anyway, display just one scroller for the control?

Thanks.

Upvotes: 0

Views: 79

Answers (2)

Chris Fannin
Chris Fannin

Reputation: 1294

The problem is that you are using a ScrollViewer on the outside of a multiline TextBox. The ScrollViewer is meant to contain a bunch of UI elements that would otherwise take up a bunch of space. The best comparison I can make is a webpage. The browser acts as a ScrollViewer, and the webpage is the contents.

If you are only needing the TextBox, you don't need the ScrollViewer. But, if you do want to use the ScrollViewer, this will get rid of the scrollbar when not needed:

        <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
            <TextBox TextWrapping="Wrap" AcceptsReturn="True" Height="240" IsReadOnly="True" VerticalScrollBarVisibility="Auto" />
        </ScrollViewer>

Upvotes: 0

ASh
ASh

Reputation: 35722

both scrolls are visible if there is too much Text for a fixed Height

try set Height for ScrollViewer

<ScrollViewer Height="240">
<TextBox TextWrapping="Wrap" AcceptsReturn="True" IsReadOnly="True"
         HorizontalScrollBarVisibility="Disabled" 
         VerticalScrollBarVisibility="Auto"
         ScrollViewer.CanContentScroll="True"/>
</ScrollViewer>

or remove ScrollViewer completely

<TextBox TextWrapping="Wrap" AcceptsReturn="True" Height="240" IsReadOnly="True"
         HorizontalScrollBarVisibility="Disabled" 
         VerticalScrollBarVisibility="Auto"
         ScrollViewer.CanContentScroll="True"/>

Upvotes: 2

Related Questions