Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout options with AndExpand are deprecated from .Net Maui for only StackLayout or all controls?

Tags:

xamarin

maui

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.

The similar post is available on Github here:

https://github.com/dotnet/maui/discussions/7346

Microsoft documentation also says same:

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?

like image 756
Divyesh_08 Avatar asked Sep 13 '25 21:09

Divyesh_08


2 Answers

All controls.

  • In Xamarin.Forms, if parent was not a StackLayout, 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.

like image 155
ToolmakerSteve Avatar answered Sep 17 '25 18:09

ToolmakerSteve


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)

like image 40
Tibuprophen Avatar answered Sep 17 '25 18:09

Tibuprophen