I tried this in my code.
<StackLayout
HorizontalOptions="FillAndExpand"
Spacing="0"
MinimumHeightRequest="50">
<StackLayout Margin="20, 6, 20, 8"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Spacing="0">
<Label Text="ABC"
HorizontalOptions="Start"
VerticalOptions="StartAndExpand" />
</StackLayout>
</StackLayout>
But with small text such as ABC then the height is not equal to 50. Is there some way I can ensure the height is a minimum of 50?
You can try to set HeightRequest=50
and measure height of your label text. Use the ITextMeter from this source, and if text height is more than 50, then set HeightRequest to text height.
You would try something like that:
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" HeightRequest="50"/>
</Grid>
I'm doing that in my application, and it works fine. You set the RowDefinition
to Auto
, then, it is going to fit exactly your HeightRequest.
Relaying what ShawnCastrianni.5092 on the following forum
After reading the remarks in the API docs, I see this:
"MinimumHeightRequest is used to override the results of a call to VisualElement.GetSizeRequest (double, double) by setting the minimum height property. This causes overflow handling to shrink this element to its minimum height before elements who do not have a minimum size set."
I guess that matches what you said Jason. Therefore, I think everybody will be thrown off by the name MinimumHeightRequest. I would prefer it say OverflowHeightRequest to avoid any confusion.
The name itself is misleading. You'll have to create a custom solution to fix your issue
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