How Can You Align a Grid Row to the Top and Bottom and Have the Middle Fill the Rest of the Screen - maui

I'm trying to build a UI where there's a small section that's always at the top of the page, and a small section that's always at the bottom. The middle section I want to have fill up the entire rest of the page height. I thought it would be something like the XAML below but it's not working - the middle section never fills up the available space. Was hoping someone could point out what I'm doing wrong. Simplified markup below:
<Grid RowDefinitions="60,*,60" ColumnDefinitions="*">
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
<!-- top stuff here -->
</HorizontalStackLayout>
<VerticalStackLayout Grid.Row="1" Grid.Column="0" VerticalOptions="Fill">
<!-- middle section here -->
</VerticalStackLayout>
<Grid Grid.Row="2" Grid.Column="0">
<!-- bottom section here -->
</Grid>
</Grid>
NOTE: When pasting into this question the editor strips out the closing <//Grid> tag.

When in doubt, use ..AndExpand to be sure all space is used.
<Grid RowDefinitions="60,*,60" ColumnDefinitions="*"
VerticalOptions="FillAndExpand" >
...
<VerticalStackLayout Grid.Row="1" VerticalOptions="FillAndExpand" ...
UPDATE
Actually, your original code does what it should for me, testing on both Windows and Android, when I set MainPage = new MainPage(); and have that code in MainPage. With a BackgroundColor on the middle part, so I can see it expand as desired.
So, what is different in your setup?
Are you using AppShell?
Testing on platform other than Windows or Android?
You didn't test the "simplified markup" you show, so the problem is elsewhere in your actual markup?

Related

Setting size of editor for chat UI in .NET MAUI app

In my .NET MAUI app, I'm implementing chat feature and want to make sure that the Editor and Button are perfectly located at the bottom of the screen.
I created a Grid for the controls to produce this layout
The problem I'm having is with the Editor width because if I get it to look right on Android, it's not perfect on iOS and vice versa.
Here's how I approached it:
<Grid
RowDefinitions="50"
ColumnDefinitions="*,50"
RowSpacing="0"
ColumnSpacing="5"
HorizontalOptions="StartAndExpand"
Margin="5,5,5,5">
<Editor
Grid.Column="0" />
<Button
Grid.Column="1" />
</Grid>
Other than entering some arbitrary number for WidthRequest for the Editor, how do I set the width for it so that it always takes up all the available space and look like it in the picture?
After setting HorizontalOptions="FillAndExpand" as Jason suggested like below, it looks right on Android and iOS.
<Grid
RowDefinitions="50"
ColumnDefinitions="*,50"
RowSpacing="0"
ColumnSpacing="5"
HorizontalOptions="FillAndExpand"
Margin="5">
<Editor
Grid.Column="0" />
<Button
Grid.Column="1" />
</Grid>

Syncfusion MAUI DataGrid and VerticalStackLayout

I would like to add label above Syncfusion Datagrid but the label is hidden when I run the app in the following page.
See the following repos for complete app.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DataGrid.Views.OrderInfoRepositoryView"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
xmlns:local="clr-namespace:DataGrid"
Title="Order Info Repository View">
<ContentPage.BindingContext>
<local:OrderInfoRepositoryViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<ContentPage.Content>
<VerticalStackLayout Margin="20"
Spacing="10">
<Label Text="OrderInfo"
Margin="10,10,10,10"
TextColor="White"
BackgroundColor="Red"/>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}">
</syncfusion:SfDataGrid>
</VerticalStackLayout>
</ContentPage.Content>
Did try the following but same result.
<Label Text="OrderInfo"
Margin="10,10,10,10"
TextColor="White"
BackgroundColor="Red"/>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}">
</syncfusion:SfDataGrid>
</VerticalStackLayout>
Here Android screenshot
Added LineHeight and fontSize. No change
Tested with HeightRequest. No change.
It appears that you have set the Content for the ContentPage as DataGrid in OrderInfoRepositoryView.xaml.cs file. Please refer to the below file,
https://github.com/JeanMarcFlamand/MauiSyncFusionExamples/blob/master/DataGrid/Views/OrderInfoRepositoryView.xaml.cs#L12
You are adding the DataGrid as the content of the page in code behind i.e., OrderInfoRepositoryView constructor. That’s why the DataGrid alone is displaying without Label. We request that you remove the codes inside the OrderInfoRepositoryView constructor to overcome the issue.

AbsoluteLayout proportional position flag not working properly in .net MAUI

I'm trying to position a StackLayout to the bottom of the page using an AbsoluteLayout as demonstrated in below code sample. However the position flag is treated as absolute value not proportional resulting in having the StackLayout positioned in the top of the page (rather in the bottom). When I inclemently increase the position value, the StackLayout starts to shift downward which it should not since the the layoutFlags are set to "All". Any help would be appreciated in help to resolve this issue, is it a bug in .net MAUI?
<AbsoluteLayout Margin="5">
<StackLayout BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0,1,1,0.2"
AbsoluteLayout.LayoutFlags="All">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="التاريخ المحدد:"/>
<Label x:Name="selectedDeliveryDate"/>
</StackLayout>
<Button x:Name="confirmDateSelected" Text="تأكيد" BackgroundColor="#009688" Margin="20,5,20,5" Clicked="confirmDateSelected_Clicked"/>
</StackLayout>
</AbsoluteLayout>
It works for me.
The problem is something you don't show:
What did you place <AbsoluteLayout ... inside of?
The proportions of AbsoluteLayout are relative to whatever layout it is inside of.
Here I've taken your code, but changed background color to "Red", and placed it directly inside a page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp7t.Page3"
Title="Page3">
<AbsoluteLayout Margin="5">
<StackLayout BackgroundColor="Red"
AbsoluteLayout.LayoutBounds="0,1,1,0.2"
AbsoluteLayout.LayoutFlags="All">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="التاريخ المحدد:"/>
<Label x:Name="selectedDeliveryDate"/>
</StackLayout>
</StackLayout>
</AbsoluteLayout>
</ContentPage>
This does what you describe: My "red" area is at bottom of screen:
Tested on both Windows and Android.
Tested both as a stand-alone page, and as a page within AppShell.

Textfields aren't stretching when in same Grid with react-select Select

This is a recent issue and this only happens on Chrome (Version 76.0.3809.132). I've got a real simple dialog that contains a material ui (v4.3.3) Grid, some TextFields and 2 react-select(v3.0.4) Select boxes. The container is setup with justify flex-start and alignItems stretch. The input controls are simply wrapped up in Grid items all with fullWidth set on them. The issue I'm seeing is that on render, the TextFields don't stretch the entire width of the Grid while the Selects do. Here's where it gets interesting, if I tab cycle focus through the components the TextFields will snap to full width as soon as the react-select Select component gets focus, this also occurs if I just click into the react-select Select component. If I shift-tab cycle back to the TextFields, they snap back to their original stunted width.
If I remove the Selects from the Grid, the TextFields stretch the width of the container as expected. I've removed all custom styling from the react-select Select and it still exhibits the same behavior (TextFields displaying not at full width). I also tried a separate 3rd party react wrapper around react-select, react-select-material-ui, and it still exhibits the same behavior.
<Grid
container
direction="column"
justify="flex-start"
alignItems="stretch"
>
<Grid item>
<Select ... />
</Grid>
<Grid item>
<TextField ... />
</Grid>
<Grid item>
<TextField ... />
</Grid>
<Grid item>
<TextField ... />
</Grid>
<Grid item>
<Select ... />
</Grid>
</Grid>
As mentioned, this was working as expected until recently and only happens in Chrome. My expectation is that the TextFields will render the full width of the container consistently.
The latest version of Chrome (Version 77.0.3865.75) appears to have fixed a rendering issue. Things are rendering as expected now.

Xaml Xamarin Forms Absolute Layout Overlap

Given the above image, how would I go about to setup my Absolute Layouts?
I would like to have my blue absolute layout overlap the red border absolute layout. I understand there's a doc explaining how AbsoluteLayouts work however I still don't completely understand it 100%.
I have tried setting up the layouts the following way but the blue square is always hidden.
With the below code I don't end up seeing the blue layout at all.
<AbsoluteLayout>
<AbsoluteLayout x:Name="BlueSquare">
<StackLayout> (Asumme there is a list of things in here) </StackLayout>
</AbsoluteLayout>
<AbsoluteLayout x:Name="RedBorderArea">
<StackLayout> (Asumme there is another list of stuff in here) </StackLayout>
</AbsoluteLayout>
</AbsoluteLayout>
After tinkering around I needed to add the Blue square layout last and i removed the RedSquares parent layout.
<AbsoluteLayout>
<StackLayout x:Name="RedBorderArea" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"> (Asumme there is another list of stuff in here) </StackLayout>
<AbsoluteLayout x:Name="BlueSquare" LayoutFlags="PositionProportional, WidthProportional" LayoutBounds="1,0,1,1">
<StackLayout> (Asumme there is a list of things in here) </StackLayout>
</AbsoluteLayout>
</AbsoluteLayout>