Nick Heiner
Nick Heiner

Reputation: 122412

Silverlight: Scrollviewer only appears when content overflows?

I'm using Silverlight 4. I have a UserControl whose LayoutRoot is wrapped in a ScrollViewer. I'd like the scroll bar to only appear if the LayoutRoot overflows the page. It is possible to do it automatically, or should I write code to detect if the content will overflow and set the scrollbar visibility accordingly?

Upvotes: 2

Views: 1433

Answers (1)

Donut
Donut

Reputation: 112795

You should be able to do it automatically using the ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility properties. Here's a list of all possible values for those properties (the ScrollBarVisibility enumeration):

  • Disabled
  • Auto
  • Hidden
  • Visible

I think "Auto" is what you're looking for:

Auto: A ScrollBar appears and the dimension of the ScrollViewer is applied to the content when the viewport cannot display all of the content. For a horizontal ScrollBar, the width of the content is set to the ViewportWidth of the ScrollViewer. For a vertical ScrollBar, the height of the content is set to the ViewportHeight of the ScrollViewer.

Hope this helps!

Upvotes: 4

Related Questions