microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.35k stars 677 forks source link

Is IScrollSnapPointsInfo expected to work with ScrollView? #9585

Open jumhyn-browser opened 6 months ago

jumhyn-browser commented 6 months ago

Describe the bug

Creating a ScrollView which wraps e.g. a StackPanel does not appear to respect snap points, and doesn't have the same APIs available. Weirdly, the ScrollTo method does accept a parameter which purports to use snap point knowledge, but interaction-based scrolling doesn't appear to use them.

Is this on the roadmap for future support? Or is there an API I'm missing?

Steps to reproduce the bug

  1. Wrap a StackPanel with content in a ScrollViewer (and set appropriate snap point mode)
  2. Observe snap points respected
  3. Change ScrollViewer to a ScrollView (remove snap point mode setting since the API doesn't exist)
  4. Observe snap points not respected

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Windows version

No response

Additional context

No response

RBrid commented 4 months ago

The new ScrollPresenter and ScrollView controls indeed do not support the IScrollSnapPointsInfo interface.

That is a feature that we are considering for a future release.

In the meantime, it requires some work on the app side to have effective snap points. You need to manually add them to the inner ScrollPresenter. Look for ScrollSnapPoint, RepeatedScrollSnapPoint (if the StackPanel has equally sized items) classes.

ScrollPresenter has these properties that you can use:

    Windows.Foundation.Collections.IVector<ScrollSnapPointBase> HorizontalSnapPoints { get; };
    Windows.Foundation.Collections.IVector<ScrollSnapPointBase> VerticalSnapPoints { get; };

(And also
Windows.Foundation.Collections.IVector<ZoomSnapPointBase> ZoomSnapPoints { get; };
which you probably do not care about.)

To access the inner ScrollPresenter, use ScrollView's Microsoft.UI.Xaml.Controls.Primitives.ScrollPresenter ScrollPresenter{ get; };

Example:

    ScrollSnapPoint snapPoint1 = new ScrollSnapPoint(snapPointValue: 100, alignment: ScrollSnapPointsAlignment.Near);
    scrollPresenter.VerticalSnapPoints.Add(snapPoint1);

Hope this helps for now.

jumhyn-browser commented 3 months ago

@RBrid thanks for the suggested workaround! I'll give the manual approach a try