Skip to content

[Windows] Fix AspectFit image fills container regression causing UI test failures on candidate branch#35923

Merged
kubaflo merged 1 commit into
dotnet:inflight/candidatefrom
praveenkumarkarunanithi:fix-32393-candidate
Jun 15, 2026
Merged

[Windows] Fix AspectFit image fills container regression causing UI test failures on candidate branch#35923
kubaflo merged 1 commit into
dotnet:inflight/candidatefrom
praveenkumarkarunanithi:fix-32393-candidate

Conversation

@praveenkumarkarunanithi

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue.
Thank you!

Root Cause

PR #34699 introduced _cachedImageSize to eliminate timing-dependent behavior in GetDesiredSize(). As part of that change, MapSourceAsync() resets the cache to Zero whenever a new image source is assigned.

However, GetDesiredSize() was updated to rely exclusively on _cachedImageSize and no longer considered the live decoded size available on BitmapSource. This created a timing gap where WinUI had already completed image decoding and populated BitmapSource.PixelWidth/PixelHeight, but the asynchronous ImageOpened event had not yet fired to update the cache.

If a layout pass occurred during this window, GetDesiredSize() observed a zero-sized cache, skipped the natural-size constraint, and allowed the image to expand to the available container size instead of respecting its decoded pixel dimensions.

Description of Change

Two minimal updates were made in ImageHandler.Windows.cs:

GetDesiredSize()

  • Reads the live decoded size from BitmapSource first.
  • Falls back to _cachedImageSize only when the live size is not yet available.
  • Aligns with the existing live-first, cache-fallback pattern already used in UpdatePlatformMaxConstraints().

GetImageSize()

  • Added a null-conditional guard for PlatformView to prevent a potential null-reference exception when GetDesiredSize() is called after handler disconnection.

Regression Introduced By

PR #34699

Issues Fixed

Fixes the following candidate branch regressions:
In Issue30403SmallImages.cs file:
ConstrainedContainers_ShouldHandleSmallImages
SmallImageEndAlignment_ShouldRespectAlignment
SmallImageInLargeContainer_ShouldNotExceedIntrinsicSize
SmallImageStartAlignment_ShouldRespectAlignment
SizeComparison_ShouldShowDifferentSizes
TinyImage_ShouldRemainTiny

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

@praveenkumarkarunanithi praveenkumarkarunanithi added platform/windows area-controls-image Image control i/regression This issue described a confirmed regression on a currently supported version labels Jun 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jun 15, 2026
@vishnumenon2684 vishnumenon2684 added the community ✨ Community Contribution label Jun 15, 2026
@sheiksyedm sheiksyedm marked this pull request as ready for review June 15, 2026 17:11
@sheiksyedm sheiksyedm requested a review from kubaflo June 15, 2026 17:11
@kubaflo kubaflo merged commit c1ba08c into dotnet:inflight/candidate Jun 15, 2026
38 of 41 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR9 milestone Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-image Image control community ✨ Community Contribution i/regression This issue described a confirmed regression on a currently supported version partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants