Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing the scrollbar visibility of a ListBox in code-behind

How to check whether the vertical scrollbar of the listbox is visible in code-behind?

I have a listbox with x:Name="listOfItems" and its underlying ScrollViewer's VerticalScrollbarVisibility is set to auto.

When the ItemsSource property of the ListBox is set, I want to check whether the verticalScrollbar is visible, but I don't know which property to check or how to dive into the scrollviewer element of the listbox.

Any suggestions

like image 383
Kornelije Petak Avatar asked Apr 27 '09 08:04

Kornelije Petak


1 Answers

You can find Listbox' ScrollViewer as described here: WPF - Animate ListBox.ScrollViewer.HorizontalOffset?

Then you can use ComputedVerticalScrollBarVisibility property to check if the scrollbar is visible:

ScrollViewer sv = FindVisualChild<ScrollViewer>(listOfItems);
Visibility scrollbarVisibility = sv.ComputedVerticalScrollBarVisibility;
like image 198
Stanislav Kniazev Avatar answered Nov 15 '22 07:11

Stanislav Kniazev