\n
This is what I am trying, but no combination of options seems to work:
\n<HorizontalStackLayout HorizontalOptions="FillAndExpand">\n <BoxView BackgroundColor="Green" HorizontalOptions="Start" WidthRequest="200"></BoxView>\n <BoxView BackgroundColor="Blue" HorizontalOptions="FillAndExpand"></BoxView>\n</HorizontalStackLayout> \n
\nThis is all I ever get in Maui without setting an explicit width:
I have tried Start, StartAndExpand, FillAndExpand, nothing works. What am I doing wrong?
\n","author":{"@type":"Person","name":"Sarah Shelby"},"upvoteCount":8,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"It looks like I was able to accomplish my goal by using a Maui Grid
. It seems there was discussion here, stating the following:
\n\nWith this pull request I am proposing the following:
\n\n
\n- The "AndExpand" options will not go into MAUI Core.
\n- The "AndExpand" options in Controls will be marked Obsolete
\n- The Controls implementation of StackLayout will, for the time being, honor the "AndExpand" options. We may choose to remove that capability in the future.
\n- No new form of the "AndExpand" options will be added to any future versions of Core or Controls.
\nThis pull request marks all of the "AndExpand" LayoutOptions in Controls as Obsolete. Current usages are preserved with warnings disabled.
\nThe pull request also adds "AndExpand" legacy capabilities to the new StackLayout. When the new StackLayout detects the use of "AndExpand" it will drop into a separate mode which lays out child views as expected. VerticalStackLayout and HorizontalStackLayout do not honor "AndExpand" - only StackLayout does this. This is to ease the transition for existing Xamarin.Forms applications.
\nAll of the functionality provided by "AndExpand" is already available to layouts via the Grid, so no new attached properties or other StackLayout->specific properties are required.
\n
This is the solution:
\n<Grid>\n <Grid.ColumnDefinitions>\n <ColumnDefinition Width="200" />\n <ColumnDefinition />\n </Grid.ColumnDefinitions>\n <BoxView BackgroundColor="Green" Grid.Column="0" />\n <BoxView BackgroundColor="Blue" Grid.Column="1" />\n</Grid>\n
\nThis results in the following layout:\n
Reputation: 451
I am trying to design an interface where there is a pane on the left and a another pane that expands to fit the remaining space. I attempted to do this with a HorizontalStackLayout
, but no matter what I do, I can't get the second pane to appear without setting a specific WidthRequest
. This is a demonstration of how I want it to look:
This is what I am trying, but no combination of options seems to work:
<HorizontalStackLayout HorizontalOptions="FillAndExpand">
<BoxView BackgroundColor="Green" HorizontalOptions="Start" WidthRequest="200"></BoxView>
<BoxView BackgroundColor="Blue" HorizontalOptions="FillAndExpand"></BoxView>
</HorizontalStackLayout>
This is all I ever get in Maui without setting an explicit width:
I have tried Start, StartAndExpand, FillAndExpand, nothing works. What am I doing wrong?
Upvotes: 8
Views: 16306
Reputation: 1854
According to Microsoft Documentation both the VerticalStackLayout and HorizontalStackLayout ignore *AndExpand
suffixes. This is a change in behavior from the StackLyout from Xamarin.Forms. However, for backwards compatibility StackLayout still behaves the same but if you use AndExpand
you will get a warning.
Upvotes: 2
Reputation: 1791
From what I have seen in the .Net Maui Git branch change comments - both the horizontal and vertical stack layouts ignore any layout options that have "andexpand" in them. In my project, in needed to convert every thing that used 'andexpand' back to a regular stack layout with the orientation set to horizontal or vertical as needed. Then the 'andexpand' options were respected.
Upvotes: 2
Reputation: 451
It looks like I was able to accomplish my goal by using a Maui Grid
. It seems there was discussion here, stating the following:
With this pull request I am proposing the following:
- The "AndExpand" options will not go into MAUI Core.
- The "AndExpand" options in Controls will be marked Obsolete
- The Controls implementation of StackLayout will, for the time being, honor the "AndExpand" options. We may choose to remove that capability in the future.
- No new form of the "AndExpand" options will be added to any future versions of Core or Controls.
This pull request marks all of the "AndExpand" LayoutOptions in Controls as Obsolete. Current usages are preserved with warnings disabled.
The pull request also adds "AndExpand" legacy capabilities to the new StackLayout. When the new StackLayout detects the use of "AndExpand" it will drop into a separate mode which lays out child views as expected. VerticalStackLayout and HorizontalStackLayout do not honor "AndExpand" - only StackLayout does this. This is to ease the transition for existing Xamarin.Forms applications.
All of the functionality provided by "AndExpand" is already available to layouts via the Grid, so no new attached properties or other StackLayout->specific properties are required.
This is the solution:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="Green" Grid.Column="0" />
<BoxView BackgroundColor="Blue" Grid.Column="1" />
</Grid>
This results in the following layout:
Upvotes: 9