Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollViewer isn't consistently anchoring the viewport to track a growing extent #562

Open
micahl opened this issue Apr 15, 2019 · 4 comments
Labels
area-Scrolling bug Something isn't working team-Controls Issue for the Controls team

Comments

@micahl
Copy link
Contributor

micahl commented Apr 15, 2019

Describe the bug

When scrolled to the bottom of a list with a ScrollViewer that is configured to anchor at the extent (VerticalAnchorRatio = 1.0) then the viewport should automatically shift to track the very end, but it doesn't always.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Clone the https://github.com/micahl/bottomsuplist repo
  2. Checkout the oldscrollviewer branch which uses the Windows.UI.Xaml.Control.ScrollViewer to host an ItemsRepeater
  3. Build and run the solution
  4. Ensure you're scrolled all the way to the bottom.
  5. Enter a few text messages in quick succession.

Expected behavior

The newly added messages at the bottom of the list should always appear in view.

Actual behavior
The viewport may not automatically shift so that the message doesn't appear in view and at that point it tracks what is in view so that all subsequent messages continue to appear below the fold.

Version Info

NuGet package version:
Microsoft.UI.Xaml 2.1.190405004]

Windows 10 version Saw the problem?
Insider Build (18362) Yes
October 2018 Update (17763) Yes
Device form factor Saw the problem?
Desktop Yes
@michaelosthege
Copy link

michaelosthege commented Nov 29, 2019

What a ride 😲.
After an hour of testing autoscroll behaviors from StackOverflow (they were all using outdated UWP APIs) I was excited to learn about VerticalAnchorRatio and re-targeted my app to 1809 😃

Then this bug.. Again back to the attached properties, but in the end I gave up on them 🤧, set the x:Name and used this extension method:

/// <summary>
/// This is a workaround for https://github.com/Microsoft/microsoft-ui-xaml/issues/562
/// 
/// When the issue is fixed, ScrollViewers can be set to VerticalAnchorRatio="1"
/// </summary>
public static class ScrollViewerExtensions
{
    public static void EnableAutoscroll(this ScrollViewer scroller)
    {
        FrameworkElement content = scroller.Content as FrameworkElement;
        if (content == null)
        {
            throw new NullReferenceException("ScrollViewer has no content to monitor for size changes.");
        }
        bool _autoScroll = true;
        scroller.ViewChanged += delegate
        {
            // autoscroll only if the view-changed stopped at the end
            _autoScroll = scroller.ScrollableHeight - scroller.VerticalOffset < 0.1;
        };
        content.SizeChanged += delegate
        {
            if (_autoScroll)
            {
                scroller.ChangeView(null, scroller.ExtentHeight, null);
            }
        };
    }
}

@RBrid
Copy link
Contributor

RBrid commented Dec 3, 2019

Thanks for the report @michaelosthege and sorry for the troubles. I am not sure how quickly we will be able to investigate this. In the meantime, I am concerned about the strict equality above, scroller.VerticalOffset == scroller.ScrollableHeight, because of rounding errors.
The ScrollViewer uses a 0.1px tolerance, so it would become something like:
_autoScroll = scroller.ScrollableHeight - scroller.VerticalOffset < 0.1;
Thanks.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@michaelosthege
Copy link

@RBrid was this maybe taken care of in the meantime?

@duncanmacmichael duncanmacmichael added bug Something isn't working and removed area-ItemsRepeater labels Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Scrolling bug Something isn't working team-Controls Issue for the Controls team
Projects
No open projects
Development

No branches or pull requests

5 participants