Home > Blockchain >  How to set width as a percentage of the parent in XAML
How to set width as a percentage of the parent in XAML

Time:11-08

How can i set the width of a view as a percentage of the parent? I tried with WidthRequest=0.2* but this seems to only work for grids. Is there a way to set it similarly for any other view or is my only option to set it programatically?

<?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="SnipSnip.SnippetsPage"
             Title="SnippetsPage">
    <AbsoluteLayout>
        <ListView x:Name="SnippetsListView">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell Text="{Binding Name}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <Editor/>
    </AbsoluteLayout>
</ContentPage>

In this sample, i want the ListView to have a width of .2* and the Editor to have a width of .8*

Thanks

CodePudding user response:

I also think you should just use a grid instead. An AbsoluteLayout is just what it says: its absolute. There is no way to let it automatically use just half of the space it has or something like that. Thats what the grid is for.

  • Related