AutoSuggestBox scrolling

Brent Esh 1 Reputation point
2021-07-28T14:38:35.407+00:00

The AutoSuggestBox suggestions list seems really inconsistent with its scrolling, especially when it appears above the AutoSuggestBox.

I found that when the items source collection changes, the listview usually scrolls to the top rather than to the first item (the first item is at the bottom when the popup is above the AutoSuggestBox). I also noticed that sometimes when the popup is below the AutoSuggestBox it will sometimes show the first item scrolled out of view. And other times it will scroll randomly to the center of the list.

I dealt with it using this ugly code but I'd rather use a more standard implementation:

                *if (AssociatedObject?.IsSuggestionListOpen == true && Popup != null && Popup.HorizontalOffset == 0)//still open, opening above or below
                {
                    var border = (Border)Popup.Child;
                    var listView = (ListView)border.Child;
                    if (listView.ItemsSource != null && VisualTreeHelper.GetChildrenCount(border.Child) > 0)
                    {
                        var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(listView, 0), 0);
                        var scrollLocation = Popup.VerticalOffset < 0 ? scrollViewer.ScrollableHeight : 0;
                        scrollViewer.ChangeView(null, scrollLocation, null, disableAnimation: true);
                    }
                }*
Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.