microsoft / microsoft/microsoft-ui-xaml

ScrollView scrollbars do not disappear when zoomed to fit with no animation

Open
#11,076 0 comments 0 reactions 0 assignees View on GitHub
area-ScrollBar area-Scrolling bug
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

I have a `ScrollView` displaying an image that is larger than the viewport and with the scrollbar visibilities in both directions set to auto. When loading the image, I call `ZoomTo()` with `ScrollingAnimationMode.Disabled` to set the initial zoom to fit the viewport. The content fully fits within the view, but the scrollbars do not disappear despite not being able to scroll. If I allow it to animate, then the scrollbars disappear, but the animation is distracting.

### Why is this important?

Having the scrollbar still visible despite not being able to scroll is confusing.

### Steps to reproduce the bug

1. Create a page containing
```xml

```
2. In the .cs file, add
```cs
var image = // load a SoftwareBitmap that is larger than the ScrollView
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(image);

Image.Width = image.PixelWidth;
Image.Height = image.PixelHeight;
Image.Source = source;

// Fit the image to a slightly smaller size than the view to make sure
// rounding error doesn't result in it being slightly bigger.
var scale = (float)Math.Min(
(ScrollView.ActualWidth - 2) / image.PixelWidth,
(ScrollView.ActualHeight - 2) / image.PixelHeight
);

ScrollView.ZoomTo(scale, null, new ScrollingZoomOptions(ScrollingAnimationMode.Disabled));
```

### Actual behavior

The ScrollView immediately zooms to fit the image, but the scrollbars still appear as if the image was at its original zoom level. It is not possible to scroll by grabbing the scrollbar handles or using the mouse wheel, but clicking on one of the arrows on the scrollbars causes it to briefly scroll in that direction, and then the scrollbars disappear and it recenters the image in the view. Zooming out further also makes the scrollbars disappear.

### Expected behavior

The scrollbars should disappear, since it is not possible to scroll.

### Screenshots

This is a 2048 x 2048 black image drawn inside a much smaller ScrollView (with magenta background) and zoomed to fit as described above.

Image

### NuGet package version

1.8.260416003

### Windows version

Windows 11 (24H2): Build 26100

### Additional context

If `new ScrollingZoomOptions(ScrollingAnimationMode.Disabled)` is removed from the code, it zooms out from the upper left corner of the image, and the scrollbar disappear as expected. This initial zoom is distracting though.

Contributor guide

Open the contributing guide

Research direction

Start with the .cs reproduction using ScrollView.ZoomTo and ScrollingZoomOptions with animation disabled, confirming the scrollbar state after the image fits. Trace the ScrollView zoom and scrollbar update path, then verify that disabled zooming hides the scrollbars when the content can no longer scroll.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.