Fix Image control not respecting VerticalOptions and HorizontalOptions on Windows#30635
Closed
Fix Image control not respecting VerticalOptions and HorizontalOptions on Windows#30635
Conversation
Co-authored-by: jsuarezruiz <6755973+jsuarezruiz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Image under WinUI does not respect VerticalOptions and HorizontalOptions
Fix Image control not respecting VerticalOptions and HorizontalOptions on Windows
Jul 15, 2025
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
According to @morning4coffe-dev this is not the right way and has opened #30936 instead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
VerticalOptionsandHorizontalOptionsproperties, 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.cswas missing mappings forHorizontalLayoutAlignmentandVerticalLayoutAlignmentproperties 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 MAUILayoutAlignmentto WindowsHorizontalAlignmentUpdateVerticalLayoutAlignment()- Maps MAUILayoutAlignmentto WindowsVerticalAlignmentUpdated property mapper in
ImageHandler.csto 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
Issue30403with 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.