Nish
Nish

Reputation: 35

Silverlight ScrollViewer, Find if vertical Scrolling is enable

I have a Scroll viewer

<ScrollViewer x:Name="sViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"/>

Now after load, how can I find if the scroll Viewer is scroll-able vertically. i.e. is the Vertical Scrollbars are visible or Collapsed.

I tried to read Visibility property,

ScrollBar verticalScrollBar = ((FrameworkElement)VisualTreeHelper.GetChild(sViewer, 0)).FindName("VerticalScrollBar") as ScrollBar;

but every time i get Visibility as Collapsed, even when the Scrolling is available.

Will appreciate your help.

Upvotes: 2

Views: 511

Answers (1)

Jimmy W
Jimmy W

Reputation: 539

Use ScrollBar.ScrollableHeight and ScrollBar.ScrollableWidth. Value > 0 means that there are scroll bars.

You can also use ScrollViewer.ComputedVerticalScrollBarVisibility and ScrollViewer.ComputedHorizontalScrollBarVisibility.

Upvotes: 2

Related Questions