10

Is there a way to create a ScrollViewer which only allows content to scroll vertically? The horizontal (width) must be constrained in the same manner as a StackPanel's width is constrained to its parent (when HorizontalAlignment=Stretch).

I have a resizable window which contains content I want to allow to scroll vertically. The window contains a ScrollViewer. Inside there is a lot of TextBoxs (a data entry form). When I type lots of text in a TextBox, the control just keeps growing to the right, and off the window. If I use a StackPanel instead of a ScrollViewer, then the size of the TextBox remains the same no matter how much text is in there. (but then no vertical scrolling).

I cant set a hard-coded Width because the window is resizable.

So basically I want to constrain the ScrollViewer from growing in the Horizontal direction.

Thanks

Matt
  • 362
  • 5
  • 21

1 Answers1

21

Try setting

<ScrollViewer HorizontalScrollBarVisibility="Disabled">
Justin XL
  • 38,763
  • 7
  • 88
  • 133
  • 2
    Wow. So simple. I cant believe I missed that. I guess the "Visibility" part of HorizontalScrollBarVisibility property just made me think it would not affect the behavior of the scrollviewer, just the visibility of the scroll bar. – Matt Oct 07 '11 at 18:04
  • yeah i agree the name is confusing. :) – Justin XL Oct 08 '11 at 01:02