Fix Image control not respecting VerticalOptions and HorizontalOptions on Windows #30635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!
Problem
Image controls under WinUI were not respecting their
VerticalOptions
andHorizontalOptions
properties, causing them to stretch to fill the available space instead of being positioned according to their alignment settings.Before (WinUI):

Expected (Android behavior):

Root Cause
The
ImageHandler.Windows.cs
was missing mappings forHorizontalLayoutAlignment
andVerticalLayoutAlignment
properties to the corresponding Windows platform alignment properties. This caused Images with settings likeVerticalOptions="Center"
andHorizontalOptions="Center"
to be ignored on Windows.Solution
Added layout alignment extension methods in
ImageViewExtensions.cs
:UpdateHorizontalLayoutAlignment()
- Maps MAUILayoutAlignment
to WindowsHorizontalAlignment
UpdateVerticalLayoutAlignment()
- Maps MAUILayoutAlignment
to WindowsVerticalAlignment
Updated property mapper in
ImageHandler.cs
to include alignment properties for Windows platformImplemented mapping methods in
ImageHandler.Windows.cs
:MapHorizontalLayoutAlignment()
andMapVerticalLayoutAlignment()
SetupContainer()
to apply alignment when container is createdEnhanced UpdateAspect method to clear alignment properties for non-AspectFill cases, allowing layout alignment to take precedence while preserving existing AspectFill center alignment behavior
Alignment Mapping
Testing
Issue30403
with multiple alignment scenariosFiles Changed
src/Core/src/Platform/Windows/ImageViewExtensions.cs
- Added alignment mapping methodssrc/Core/src/Handlers/Image/ImageHandler.cs
- Added alignment property mappings for Windowssrc/Core/src/Handlers/Image/ImageHandler.Windows.cs
- Implemented alignment mapping methodssrc/Controls/tests/TestCases.HostApp/Issues/Issue30403.xaml[.cs]
- Test casesrc/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30403.cs
- UI testFixes #30403.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.