microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Unable to scroll in horizontal ItemsView using mouse wheel

Open tipa opened this issue 6 months ago • 5 comments

Describe the bug

When setting up a ItemsView with a StackLayout that has Orientation="Horizontal" set, I cannot scroll through the list using the mouse wheel. This was and is possible with ListView when using a ItemsStackPanel with Orientation="Horizontal"

Steps to reproduce the bug

<ItemsView>
  <ItemsView.Layout>
    <StackLayout Orientation="Horizontal"  />
  </ItemsView.Layout>
...
</ItemsView>

Expected behavior

I can scroll through the list using the mouse wheel

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.7.2: 1.7.250513003

Windows version

Windows 11 (24H2): Build 26100

Additional context

This bug report is likely related: https://github.com/dotnet/maui/issues/22680

tipa avatar Jun 06 '25 14:06 tipa

Agreed, and the ItemsView/ScrollView does not expose any useful scroll control methods at all, making it almost impossible to simulate user scrolling or accelerate scrolling.

Poker-sang avatar Jun 07 '25 04:06 Poker-sang

Hello @tipa, can you please add a minimal repro application here which contains both ListView & ItemsView in same window with highlighting the problem you are facing ItemsView? It would help in triaging the issue faster

Hemantxk avatar Jun 13 '25 07:06 Hemantxk

@Hemantxk Sure - here's an example project: test.zip

tipa avatar Jun 13 '25 08:06 tipa

@tipa Thanks for providing the sample.

There is an existing proposal for adding this functionality to scroll view: https://github.com/microsoft/microsoft-ui-xaml/issues/877

In the meantime, as a workaround, you can try hooking into the PointerWheelChanged event in your ItemsView_Loaded handler:

 void ItemsView_Loaded(object sender, RoutedEventArgs e)
 {
     itemsView.ScrollView.HorizontalScrollBarVisibility = Microsoft.UI.Xaml.Controls.ScrollingScrollBarVisibility.Hidden;
     itemsView.ScrollView.VerticalScrollMode = Microsoft.UI.Xaml.Controls.ScrollingScrollMode.Disabled;
     itemsView.ScrollView.HorizontalScrollMode = Microsoft.UI.Xaml.Controls.ScrollingScrollMode.Enabled;
     
    //PointerWheelChanged event for horizontal scrolling
     itemsView.ScrollView.PointerWheelChanged += (sender,e) =>
     {
         var delta = e.GetCurrentPoint(itemsView).Properties.MouseWheelDelta;
         itemsView.ScrollView.ScrollTo(itemsView.ScrollView.HorizontalOffset - delta, itemsView.ScrollView.VerticalOffset);
     };
 }

This should help simulate horizontal scrolling behavior using the mouse wheel.

zinniaa avatar Jun 17 '25 10:06 zinniaa

Thanks for your response and workaround @zinniaa. I think it can be simplified as follows:

void ItemsView_Loaded(object sender, RoutedEventArgs e)
{
    var itemsView = sender as ItemsView;
    itemsView.ScrollView.PointerWheelChanged += (sender, e) =>
    {
        var delta = e.GetCurrentPoint(itemsView).Properties.MouseWheelDelta;
        itemsView.ScrollView.ScrollBy(-delta, 0, new ScrollingScrollOptions(ScrollingAnimationMode.Disabled));
    };
}

Unfortunately, I had to use ScrollingAnimationMode.Disabled because when animating the scroll, the scrolling experience is completely unsatisfactory, especially when trying to fast-scroll - because each scrolling event seems to cancel out the previous one, the scroll view almost doesn't scroll at all as a result.

But using ScrollingAnimationMode.Disabled can't be a long-term solution either, user expect to have a smooth scrolling experience. I am quite surprised that the linked feature proposal is over 6 years old, with many users asking for it, yet this is still not possible. It would be much appreciated if this could get some priority.

tipa avatar Jun 17 '25 11:06 tipa