Set minimum or maximum Height of Row of Grid in Xaml (Xamarin.Forms)

12,915

Solution 1

You can do this to set your MinimumHeight:

<Grid ColumnSpacing="10" Padding="20">
    <Grid.RowDefinitions>
        <RowDefinition Height= "Auto"/>
    </Grid.RowDefinitions>
    <ContentView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" MinimumHeightRequest="20">
        ...
    </ContentView>
</Grid>

Note: The MinimumHeightRequest will chose the minimum between your requested height and your requested minimum height. Source

Solution 2

I solved the problem the same or similar way as Akash Amin. In my custom control i added an empty boxview with a fixed height to set the minimum height of the row. The importent label was placed above the transparant boxview. So i did not place anything in the boxview. I did the code in codebehind in my customcontrol.

var grid = new Grid();
grid.HorizontalOptions = LayoutOptions.Fill;
grid.VerticalOptions = LayoutOptions.Start;
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto, });

var minSizer = new BoxView();
minSizer.HeightRequest = 30;
grid.Children.Add(minSizer, 0, 0);

 _label = new Label();
_label.VerticalTextAlignment = TextAlignment.Center;
_label.VerticalOptions = LayoutOptions.Center;
grid.Children.Add(_label, 0, 0);

...

(I think it is annoying that the MinimumWidthRequest and MinimumHeightRequest dont work as the most people expects them to do. In xamarin i mean.)

Share:
12,915
Ashish Kumar
Author by

Ashish Kumar

Updated on June 04, 2022

Comments

  • Ashish Kumar
    Ashish Kumar almost 2 years

    I need to set minimum height of a RowDefinition of Gridin Xamarin.Forms using Xaml or code behind. I didn't find any property like MinHeight or MaxHeight. There is only Height property for RowDefinition.

    <Grid ColumnSpacing="10" Padding="20">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    </Grid>