Description
VisualElement.WidthRequest and VisualElement.HeightRequest have a default value of 0 if an OnIdiom condition is not set. This results in an element not being visible instead of being -1 which doesn't change behavior.
Steps to Reproduce
- Set a height request to
"{OnIdiom Phone=200}".
- Run on desktop.
- Observe that the visual element has 0 height, instead of the default height it would have with no height request set.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiWidthBugApp.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ScrollView>
<VerticalStackLayout Padding="30,0"
Spacing="25"
VerticalOptions="Center"
WidthRequest="300">
<Label FontSize="32"
HorizontalOptions="Center"
SemanticProperties.HeadingLevel="Level1"
Text="Working image:" />
<!-- No height request, image stretches to fit -->
<Image HorizontalOptions="Center"
SemanticProperties.Description="Working image"
Source="dotnet_bot.png" />
<Label FontSize="32"
HorizontalOptions="Center"
SemanticProperties.HeadingLevel="Level1"
Text="Image with bug:" />
<!-- With no default set, platforms that aren't Phone have this value set to 0, making the visual element disappear instead of stretching to fit the parent like it should -->
<Image HeightRequest="{OnIdiom Phone=200}"
HorizontalOptions="Center"
SemanticProperties.Description="Defaults to height request 0 on desktop"
Source="dotnet_bot.png" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Link to public reproduction project repository
https://github.com/ZackAllen/mauiHeightRequestBug
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows
Affected platform versions
All
Did you find any workaround?
Manually setting a default of -1.
Relevant log output
No response
Description
VisualElement.WidthRequestandVisualElement.HeightRequesthave a default value of 0 if anOnIdiomcondition is not set. This results in an element not being visible instead of being -1 which doesn't change behavior.Steps to Reproduce
"{OnIdiom Phone=200}".Link to public reproduction project repository
https://github.com/ZackAllen/mauiHeightRequestBug
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows
Affected platform versions
All
Did you find any workaround?
Manually setting a default of -1.
Relevant log output
No response