.Net Maui - Grid in a Horizontal of Both ScrollView not formatting correctly - grid

I would like to add a scrollable (vertically and horizontally) Grid in a row of an outer Grid. I want to set the Grid column widths based on the GridUnitType.Star.
I can achieve this when the SrollView orientation is set to Vertical but not when set to Horizontal or Both.
The following XAML demonstrates this:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiGrids.MainPage">
<Grid Margin="20" RowDefinitions="Auto,Auto,Auto">
<Grid Grid.Row="0" ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Outer" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Outer" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Outer" Grid.Row="0" Grid.Column="2"/>
</Grid>
<ScrollView Grid.Row="1" Orientation="Horizontal">
<Grid ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Horizontal" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Horizontal" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Horizontal" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
<ScrollView Grid.Row="2" Orientation="Vertical">
<Grid ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Vertical" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Vertical" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Vertical" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
</Grid>
</ContentPage>
The column widths of the outer and vertical grid are correctly set based on the Star value but these values are ignored in the case of the horizontal grid.
Code output.
I was able to do this in Xamarin Forms but does not seem possible in Maui. Am I missing something.

Here's the code snippet below that works well on Android for the Maui, you can refer to it:
<Grid Margin="20" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" ColumnDefinitions="*,2*,3*" Grid.ColumnSpan="3">
<Label Text="Column 1 Outer" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Outer" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Outer" Grid.Row="0" Grid.Column="2"/>
</Grid>
<ScrollView Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="3">
<Grid ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Horizontal" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Horizontal" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Horizontal" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
<ScrollView Grid.Row="2" Orientation="Vertical" Grid.ColumnSpan="3">
<Grid ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Vertical" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Vertical" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Vertical" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
</Grid>

Think I am a good part the way there.
It appears unlike the vertical ScrollView the horizontal ScrollView needs to have a width or a child with a specific width.
I have named the outerGrid, the horizontalGrid and the verticalGrid in the XAML.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiGrids.MainPage">
<Grid Margin="20" RowDefinitions="Auto,Auto,Auto">
<Grid x:Name="outerGrid" Grid.Row="0" ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Outer" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Outer" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Outer" Grid.Row="0" Grid.Column="2"/>
</Grid>
<ScrollView Grid.Row="1" Orientation="Both" HorizontalScrollBarVisibility="Default" VerticalScrollBarVisibility="Default">
<Grid x:Name="horizontalGrid" ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Horizontal" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Horizontal" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Horizontal" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
<ScrollView Grid.Row="2" Orientation="Vertical" VerticalScrollBarVisibility="Default">
<Grid x:Name="verticalGrid" ColumnDefinitions="*,2*,3*">
<Label Text="Column 1 Vertical" Grid.Row="0" Grid.Column="0"/>
<Label Text="Column 2 Vertical" Grid.Row="0" Grid.Column="1"/>
<Label Text="Column 3 Vertical" Grid.Row="0" Grid.Column="2"/>
</Grid>
</ScrollView>
</Grid>
and then set the grid widths in code behind based on the defaulted outerGrid width as follows:
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
outerGrid.Loaded += OuterGrid_Loaded;
this.SizeChanged += MainPage_SizeChanged;
}
private void MainPage_SizeChanged(object sender, EventArgs e)
{
horizontalGrid.WidthRequest = outerGrid.Width;
verticalGrid.WidthRequest = outerGrid.Width;
}
private void OuterGrid_Loaded(object sender, EventArgs e)
{
horizontalGrid.WidthRequest = outerGrid.Width;
verticalGrid.WidthRequest = outerGrid.Width;
}
This works in Windows when the form is displayed and resized. Also works in Android, both portrait and landscape.

Related

unable to navigate the content page when i click on button using xamarin forms

Im unable to navigate the content page when i click on button using xamarin forms. It is working on Android but not working in IOS.
Kindly check the below code.
ButtonClick Event
Navigation.PushAsync(new LeaveRequestAddEdit("insert"));
The xaml code is
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
<ContentPage.Content>
<StackLayout>
<Frame Padding="5" Margin="5,5,5,5" CornerRadius="10" HasShadow="True" BackgroundColor="White" BorderColor="LightBlue">
<Grid BackgroundColor="White" x:Name="LeaveRequestContainer">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
<RadioButton x:Name="OnedayRadioBtn" Clicked="OnedayRadioBtn_Clicked" />
<Label Text="One Day" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</StackLayout>
<StackLayout Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<RadioButton x:Name="MultipledaysRadioBtn" Clicked="MultipledaysRadioBtn_Clicked"/>
<Label Text="Multiple Days" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</StackLayout>
<Label x:Name="selectlable" Text="Select :" Margin="50,0,0,0" IsVisible="False" Grid.Row="1" Grid.Column="0" HorizontalOptions="StartAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
<DatePicker x:Name="selectdate" IsVisible="False" Date="{Binding FromDate,Mode=TwoWay}" Format="dd/MM/yyy" Grid.Row="1" Grid.Column="1" HorizontalOptions="StartAndExpand" />
<Label x:Name="fromdatelabel" Text="From Date :" IsVisible="False" Margin="50,0,0,0" Grid.Row="1" Grid.Column="0" HorizontalOptions="StartAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
<DatePicker x:Name="fromdate" IsVisible="False" DateSelected="fromdate_DateSelected" Date="{Binding FromDate,Mode=TwoWay}" Format="dd/MM/yyy" Grid.Row="1" Grid.Column="1" HorizontalOptions="StartAndExpand"/>
<Label x:Name="todatelable" Text="To Date :" IsVisible="False" Margin="50,0,0,0" Grid.Row="2" Grid.Column="0" HorizontalOptions="StartAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
<DatePicker x:Name="Todate" IsVisible="False" Date="{Binding ToDate,Mode=TwoWay}" Format="dd/MM/yyy" Grid.Row="2" Grid.Column="1" HorizontalOptions="StartAndExpand"/>
<Frame CornerRadius="10" Margin="0" Padding="0" BorderColor="LightBlue" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" >
<local1:ExtendedEditorControl x:Name="Reason" Placeholder="Enter Reason Here" IsExpandable="True" Text="{Binding ReasonForLeave,Mode=TwoWay}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" MaxLength="250" />
</Frame>
<StackLayout Orientation="Vertical" x:Name="ActionNoteStack" IsVisible="False" Grid.Row="4" Grid.ColumnSpan="2" Grid.RowSpan="2">
<Label x:Name="title" IsVisible="False" Text="Action Notes :" TextColor="Black" HorizontalOptions="Start" VerticalOptions="Center" />
<!--<Label Text="Action Notes :" WidthRequest="400" VerticalTextAlignment="Center" HorizontalOptions="FillAndExpand" TextColor="Blue"/>-->
<Frame x:Name="actionframe" IsVisible="False" CornerRadius="10" Margin="0" BorderColor="LightBlue" Padding="0">
<Label x:Name="actionNote" IsVisible="False" Text="{Binding ActionNotes,Mode=TwoWay}" Margin="5" VerticalOptions="Center" HorizontalOptions="FillAndExpand" />
</Frame>
</StackLayout>
</Grid>
</Frame>
<StackLayout Margin="5,0,5,5" Orientation="Horizontal" VerticalOptions="End">
<Button Text="Save" x:Name="btnSave" BackgroundColor="#6559D8" CornerRadius="10" TextColor="White" HorizontalOptions="FillAndExpand" Clicked="btnSave_Clicked"/>
<Button Text="Cancel" x:Name="btnCancel" Clicked="btnCancel_Clicked" BackgroundColor="Gray" CornerRadius="10" TextColor="White" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Kindly help on this. I'm new to Xamarin forms
​You can replace the Clicked event in the RadioButton with the CheckedChanged event to make it work.

How to set ProgressBar in Xamarin

I have a question here about customizing ProgressBar. However I am not using Syncfusion. Here is my idea, it seems not perfect =]]]]]
<StackLayout Padding="12,0" Margin="0,0,0,35">
<Grid HorizontalOptions="FillAndExpand" BackgroundColor="#fff" Padding="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--group-->
<Grid Grid.Row="0" Grid.Column="0" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="0 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="0" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="Red"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="0" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="10%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
<!--group-->
<Grid Grid.Row="0" Grid.Column="1" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="10 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="1" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="#ddd"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="1" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="11%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
<!--group-->
<Grid Grid.Row="0" Grid.Column="2" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="200 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="2" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="#ddd"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="2" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="12%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
<!--group-->
<Grid Grid.Row="0" Grid.Column="3" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="300 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="3" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="#ddd"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="3" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="12%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
<!--group-->
<Grid Grid.Row="0" Grid.Column="4" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="400 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="4" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="#ddd"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="4" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="12%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
<!--group-->
<Grid Grid.Row="0" Grid.Column="5" Margin="0,0,0,-2" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="500 K" HorizontalOptions="CenterAndExpand" FontSize="12" />
</Grid>
<Grid Grid.Row="1" Grid.Column="5" HorizontalOptions="Center" VerticalOptions="Center">
<Frame HasShadow="False" Padding="0" CornerRadius="30" WidthRequest="10" HeightRequest="10" BackgroundColor="#ddd"></Frame>
</Grid>
<Grid Grid.Row="2" Grid.Column="5" Margin="0,-2,0,0" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="12%" TextColor="Red" HorizontalOptions="CenterAndExpand" FontSize="13" />
</Grid>
<!--end group-->
</Grid>
<ProgressBar Margin="35,-37.5,35,0" ProgressColor="#ddd" HeightRequest="3" HorizontalOptions="FillAndExpand" x:Name="progressbar"/>
</StackLayout>
And this is the result:
I have 2 questions:
How is the ProgressBar below the red dot I circled in the image above?
Inside .xaml.cs how can i set ProgressTo for ProgressBar. Here is how I set it up. However it doesn't work:
private async void Progress()
{
progressbar.Progress = 10000;
float progress = 2000;
await progressbar.ProgressTo(progress, 500, Easing.Linear);
}
Please help any solution. Thank you!
Because your ProgressBar is the last element in your StackLayout, it will be drawn on TOP of the previous controls
From the docs:
Progress is a float value that represents the current progress as a
value from 0 to 1. Progress values less than 0 will be clamped to 0,
values greater than 1 will be clamped to 1.

Position 1st StackLayout on page at the bottom Xamarin.Forms

I am new to Xamarin and I am trying to position my first stacklayout of the page at the bottom of the screen and then scroll to see the remaining content.
Also, I have an image as background for my content page and I am trying to use scrollview for rest of the page content. I tried other solutions on StackOverflow but they have StackLayouts VerticalOptions as Center and Start which I don’t. I want the first stacklayout to start from the bottom and no control/layout above that.
Also, this contentpage acts as a Detail page for a MasterDetailPage.
This is my contentpage so far -
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Excercise.Views.HomePage" Title="App"
NavigationPage.HasBackButton="False" BackgroundImageSource="image.jpg">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Option1"></ToolbarItem>
<ToolbarItem Text="Option2"></ToolbarItem>
</ContentPage.ToolbarItems>
<!--<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>-->
<ContentPage.Content>
<StackLayout Orientation="Horizontal" >
<ScrollView>
<StackLayout Orientation="Vertical" VerticalOptions="EndAndExpand">
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10" VerticalOptions="EndAndExpand">
<Grid VerticalOptions="EndAndExpand">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="Label1" FontSize="Large" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" ></Label>
<Label x:Name="Label2" FontSize="Medium" Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<BoxView BackgroundColor="Black" Grid.Row="1" Grid.ColumnSpan="6"></BoxView>
<Label x:Name="Label3" FontSize="Large" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="3"></Label>
<Label Text="Label4" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="3"></Label>
<Label x:Name="Label5" Grid.Row="5" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label6" Grid.Row="2" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label7" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label8" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<Label x:Name="Label9" Grid.Row="5" Grid.Column="3" Grid.ColumnSpan="2"></Label>
<CollectionView x:Name="collecview1" WidthRequest="100" Grid.Row="6" Grid.RowSpan="3" Grid.ColumnSpan="6" ItemsLayout="HorizontalList" >
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical" Padding="5,25,30,25" VerticalOptions="Center">
<Label Text="{Binding Text}"></Label>
<Image Source="{Binding Text}"></Image>
<Label Text="{Binding Text}" HorizontalTextAlignment="Center"></Label>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</Frame>
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0">
<Label Text="Label10"></Label>
<BoxView BackgroundColor="Gray" HeightRequest="2"></BoxView>
<CollectionView x:Name="collecview2" ItemsLayout="VerticalList" ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Text}" Grid.Column="0" HorizontalTextAlignment="End" ></Label>
<Label Text="Image" Grid.Column="1"></Label>
<!--<Image Source="{Binding IconSource}" Grid.Column="1"></Image>-->
<Label Text="{Binding Text}" FontAttributes="Bold" Grid.Column="2"></Label>
<Label Text="{Binding Text}" Grid.Column="3"></Label>
<Label Text="{Binding Text}" Grid.Column="4"></Label>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Grid>
</Frame>
<Frame BorderColor="Gray" CornerRadius="5" Padding="5" Margin="10">
<StackLayout>
<Label Text="Label23"></Label>
<BoxView BackgroundColor="Black" HeightRequest="2"></BoxView>
</StackLayout>
</Frame>
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
MainPage.xaml.cs
[DesignTimeVisible(false)]
public partial class MainPage : MasterDetailPage
{
public MainPage()
{
InitializeComponent();
MasterBehavior = MasterBehavior.Split;
Detail = new HomePage();
}
public MainPage(string City, string lockey,string StateID)
{
InitializeComponent();
Detail = new HomePage(City,lockey,StateID);
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:Excercise.Views"
x:Class="Excercise.MainPage" Title="App" IsPresented="False">
<MasterDetailPage.Master>
<local:MenuPage Title="MenuPage" x:Name="menuPage"></local:MenuPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:HomePage Title="HomePage" x:Name="homePage" BackgroundImageSource="raleigh.jpg"></local:HomePage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Is there anyway to achieve this? Any help is much appreciated!
Thank you so much!
I want the first stacklayout to start from the bottom and no
control/layout above that.
You can give your first stacklayout a top margin with screen height request so that it will start from the bottom.
In xaml, give a name to your StackLayout :
<StackLayout Orientation="Vertical" VerticalOptions="End" x:Name="firstStacklayout">
In code behind:
protected override void OnAppearing()
{
base.OnAppearing();
firstStacklayout.Margin = new Thickness(0, Application.Current.MainPage.Height, 0, 0);
}

Get Label aligned when in flexlayout and frame xamarin forms

I have a flexlayout when a display some items in a frame, but all the items that have labels with text on 2 lines the icon gets pushed up and the label text do not align with each other. Any suggestions of what I am doing wrong?
my code
<Grid>
<ScrollView>
<FlexLayout
Padding="8"
AlignContent="Start"
AlignItems="Start"
BindableLayout.ItemsSource="{Binding MyItems}"
Direction="Row"
JustifyContent="Start"
Wrap="Wrap">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Margin="4,4,4,4"
FlexLayout.AlignSelf="Start"
FlexLayout.Basis="{OnIdiom Phone='50%',
Tablet='33%'}">
<Frame
Margin="0"
Padding="0"
BorderColor="DarkGray"
CornerRadius="10"
HeightRequest="130"
HasShadow="True">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Image Aspect="AspectFit" Source="PhotoIcon.png"
Margin="0,20,0,0" WidthRequest="50" HeightRequest="50"/>
<Label Text="{Binding Name}" Margin="0,10,0,10" />
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
</ScrollView>
</Grid>
Improve your code
<Label Text="{Binding Name}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="0,10,0,10" />
Update:
Because StackLayout will not fit the size of its child elements ,so I suggest you can use Grid instead of it.
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="0.5*" />
<RowDefinition Height="0.5*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Aspect="AspectFit" Source="PhotoIcon.png" Margin="0,20,0,0" WidthRequest="50" HeightRequest="50"/>
<Label Grid.Row="1" Text="{Binding Name}" Margin="0,10,0,10" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</Grid>

Autosizing images in xamarin forms layouts

i'm very new to xamarin forms so, sorry if i ask obvious question.
I need to build a frame with labels and pictures within. It should look like the following
By now i tried this:
<Frame OutlineColor="#2e5982"
BackgroundColor="#2e5982"
HorizontalOptions="Fill"
Grid.Column="0"
Margin="0">
<Frame.Content>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label x:Name="LbSecsHead" Font="Arial" TextColor="White" Text="Status" HorizontalOptions="Center"/>
<Grid HorizontalOptions="Fill" VerticalOptions="Fill">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="50*"/>
</Grid.ColumnDefinitions>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Column="0">
<StackLayout Orientation="Horizontal" BackgroundColor="Accent">
<Image x:Name="SignalSec6" Source="{local:ImageResource Fusion.Pictures.GreenSignalMaterialOff.png}" Aspect="Fill" HorizontalOptions="Start" VerticalOptions="Start"/>
<Label Font="Arial" TextColor="White" Text="6" HorizontalOptions="Center"/>
</StackLayout>
</StackLayout>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Column="1">
<StackLayout Orientation="Horizontal">
<Image x:Name="SignalSec5" Source="{local:ImageResource Fusion.Pictures.GreenSignalMaterialOn.png}" Aspect="Fill" HorizontalOptions="Start" VerticalOptions="Start"/>
<Label Font="Arial" TextColor="White" Text="5" HorizontalOptions="Center"/>
</StackLayout>
</StackLayout>
</Grid>
</StackLayout>
</Frame.Content>
</Frame>
The frame is inside a grid column of an outer layout, and here i just limited to the first two icons since result is the same for multiple identical items stacked vertically. Regardless of many tryouts i've done with Horizontal and Vertical options i always obtain this:
The frame sizing with respect to outer layout is correct but not the elements inside. Strange think (at least to me) is that picture looks like being outside of the stacklayout as can be seen by the pink background of the layout. Basically i need the pictures to autofit the layout.
Any hint would be appreciated
Thanks
You'll need to use Span :
Spans – configure elements to span across multiple rows or columns.
<Label Text="SEC" FontSize="40" HorizontalOptions="CenterAndExpand"/>
<Grid HorizontalOptions="CenterAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="80" />
<RowDefinition Height="80" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<StackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="CenterAndExpand" Orientation="Horizontal">
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="6" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="0" VerticalOptions="CenterAndExpand" Orientation="Horizontal">
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="4" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="2" Grid.Column="0" VerticalOptions="CenterAndExpand" Orientation="Horizontal">
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="2" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="3" Grid.Column="0" VerticalOptions="CenterAndExpand" Orientation="Horizontal">
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="0" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="0" Grid.RowSpan="2" Grid.Column="1"
VerticalOptions="CenterAndExpand" Orientation="Horizontal" >
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="5" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="1" Grid.RowSpan="2" Grid.Column="1"
VerticalOptions="CenterAndExpand" Orientation="Horizontal" >
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="3" FontSize="30" TextColor="Gray" />
</StackLayout>
<StackLayout Grid.Row="2" Grid.RowSpan="2" Grid.Column="1"
VerticalOptions="CenterAndExpand" Orientation="Horizontal" >
<Image HeightRequest="30" WidthRequest="30" Source="https://www.warm-glass.co.uk/images/products/20cm-deep-royal-blue-precut-glass-circle-11145052.jpg" />
<Label Text="1" FontSize="30" TextColor="Gray" />
</StackLayout>
</Grid>

Resources