When I'm using StackLayout with options like FillAndExpand, CenterAndExpand it shows this message
The StackLayout expansion options are deprecated;please use a Grid instead.
Because now we HorizontalStackLayout and VerticalStackLayout.
https://github.com/dotnet/maui/discussions/7346
https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.layoutoptions.endandexpand?view=net-maui-7.0#microsoft-maui-controls-layoutoptions-endandexpand
The question is does this applies to all other controls as well in .Net maui like Label, Button, Image, Entry etc; or it is just for StackLayout?
All controls.
AndExpand
had no effect anyway. AndExpand
is not meaningful inside any other layout. Other layouts have their own way of controlling size.So message says “The StackLayout expansion options …" because taking those out from StackLayout, means they are no longer used anywhere.
Layout is always done by some Layout class. (Layout classes are those with Children: ...Layout
, Grid
.) Setting a layout option on an element, is telling its PARENT what to do (for the given element).
Additional info about layouts:
Xamarin.Forms MAUI.Controls Layout Differences.
IMPORTANT (from that link):
For simplicity of migration from Forms to MAUI, the MAUI.Controls
StackLayout
does honor "AndExpand", at least for the time being.
That means Children of StackLayout can use ..AndExpand
, and have it take effect. For now. BUT this is "deprecated" (may go away), and not recommended (affects performance).
Instead of StackLayout
, for performance, use Vertical/HorizontalStackLayout
or Grid
or CollectionView with ItemsLayout.
Yes. This does apply to all controls. The layout options are to arrange and position controls. Microsoft recommends using Grids instead of Stacklayout to arrange and position controls instead of using *AndExpand due to performance issues (already mentioned in your linked posts)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With