I'm trying to convert my native Xamarin.iOS to Xamarin.Forms and struggle with an easy layout problem. What I am trying to achieve is a Menu like this the red Grid:
So the height of each Gridelement should be equal the width but all I get is this one:
My Xaml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<mvvm:BaseContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mvvm="clr-namespace:SharpLibrary.Forms.Source.MVVM;assembly=SharpLibrary.Forms"
xmlns:cc="clr-namespace:Gorilla.Forms.Source.UI.CustomControls"
x:Class="Gorilla.Forms.Source.UI.Guest.GuestMainPage">
<ContentPage.Content>
<RelativeLayout
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
>
<Image Style="{StaticResource StandardBackgroundImage}" />
<ScrollView
RelativeLayout.WidthConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Height}"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<cc:GridMenuItem
x:Name="testBox"
Grid.Row="0" Grid.Column="0"
BackgroundColor="Red"
Title="Test"
Icon="Text" />
<Frame
x:Name="testFrame"
Grid.Row="0" Grid.Column="1"
BackgroundColor="Gray"
HeightRequest="{Binding WidthRequest}">
<Label Text="gdjfgzhg" />
</Frame>
</Grid>
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</mvvm:BaseContentPage>
I can't figure out what I do wrong, also I found some Threads where people wanted to achieve the same thing as I do, but it does not do what I expect.
Hope someone knows the answer
I suggest you to use the following layout for your need:
<!-- No need to use AbsoluteLayout or Constraint-->
<Grid>
<Image Style="{StaticResource StandardBackgroundImage}" />
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Width responsive dependending on Screen, and Width (not WidthRequest) equals (Binding with source equals to itself)-->
<cc:GridMenuItem x:Name="testBox"
Grid.Row="0" Grid.Column="0"
HeightRequest="{Binding Width, Source={x:Reference testBox}}"
BackgroundColor="Red"
Title="Test"
Icon="Text" />
<Frame x:Name="testFrame"
Grid.Row="0" Grid.Column="1"
BackgroundColor="Gray"
HeightRequest="{Binding Width, Source={x:Reference testFrame}}">
<Label Text="gdjfgzhg" />
</Frame>
</Grid>
<ScrollView>
</Grid>
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