dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.15k stars 1.74k forks source link

HorizontalOption End does not work on a HorizontalStackedLayout on both Android and iOS #20952

Open czuck opened 7 months ago

czuck commented 7 months ago

Description

All 4 of the Entry controls below were set with HorizontalLayout = End. The two top ones in a VerticalStackedLayout appear at the end of the layout, the two bottom ones in a HorizontalStackedLayout do not. All 4 controls should be alligned. image

Steps to Reproduce

Run the linked project. Look at the output.

Link to public reproduction project repository

https://github.com/czuck/iOS-Entry

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

iOS 17.3.1, Android 14.0

Did you find any workaround?

No response

Relevant log output

No response

PureWeen commented 7 months ago

@czuck I'm pretty sure this is by design.

Horizontal StackLayout just measures to the width of all the controls so it will ask the control what size it wants to be with infinite space. It isn't going to have empty space on the left or right.

You most likely want to use a grid for this scenario.

ghost commented 7 months ago

Hi @czuck. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

czuck commented 7 months ago

Interesting .. in reading the HorizontalStackLayout documentation HorizontalOptions is not mentioned at all, only VerticalOptions. Yet in both XAML and code, HorizontalOptions autocompletes as a valid property and cand be set to Center, Start, End, or Fill, and it shows the 'AndExpand' versions as obsolete. There are also no compiler errors or warnings to indicate that this is no longer a valid option. For someone coming from Forms, which honored both Horizontal and Vertical options regardless of the orientation of the stack, there is no indication that this is no longer expected to work. This feels more like a FlexLayout. Converting to grids is not a great option.

eclipsed4utoo commented 7 months ago

For someone coming from Forms, which honored both Horizontal and Vertical options regardless of the orientation of the stack, there is no indication that this is no longer expected to work. This feels more like a FlexLayout. Converting to grids is not a great option.

In Xamarin.Forms, using Orientation="Horizontal" on a StackLayout, then attempting to use the HorizontalOptions on child elements, does not work either. It's by design, in the same way that VerticalOptions on child elements inside a Orientation="Vertical" StackLayout aren't honored either.

Maui kept the same rules.

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/stacklayout#alignment

image

Zhanglirong-Winnie commented 7 months ago

Verified this issue with Visual Studio 17.10.0 Preview 2. Can repro on Android and iOS platform with sample project. https://github.com/czuck/iOS-Entry