Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Controls/src/Xaml/MarkupExtensions/OnIdiomExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ public object ProvideValue(IServiceProvider serviceProvider)

var value = GetValue();
if (value == null && propertyType.IsValueType)
{
if(bp != null)
{
object targetObject = valueProvider.TargetObject;

if (targetObject is Setter)
return null;
else
return bp.GetDefaultValue(targetObject as BindableObject);
}
return Activator.CreateInstance(propertyType);
}

if (Converter != null)
return Converter.Convert(value, propertyType, ConverterParameter, CultureInfo.CurrentUICulture);
Expand Down
9 changes: 9 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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="Controls.TestCases.HostApp.Issues.Issue9978"
Title="Issue9978">
<VerticalStackLayout>
<Image AutomationId="MauiImage" Source="groceries.png" HeightRequest="{OnIdiom Tablet=100}" />
</VerticalStackLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Controls.TestCases.HostApp.Issues;

[Issue(IssueTracker.Github, 9978, "VisualElement.HeightRequest defaults to 0 instead of -1 when using OnIdiom default value",
PlatformAffected.All)]
public partial class Issue9978 : ContentPage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need this test in Xaml.UnitTest so we test for all xaml inflators

{
public Issue9978()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Tests.Issues;

public class Issue9978 : _IssuesUITest
{
public Issue9978(TestDevice device) : base(device)
{
}

public override string Issue => "VisualElement.HeightRequest defaults to 0 instead of -1 when using OnIdiom default value";


[Test]
[Category(UITestCategories.Layout)]
public void Issue9978Test()
{
App.WaitForElement("MauiImage");

}
}
7 changes: 7 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?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="Microsoft.Maui.Controls.Xaml.UnitTests.Issues.Issue9978"
Title="Issue9978">
<Button x:Name="mauiButton" Text="Sample Button" HeightRequest="{OnIdiom Tablet=50}" />
</ContentPage>
52 changes: 52 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Devices;
using NUnit.Framework;

namespace Microsoft.Maui.Controls.Xaml.UnitTests.Issues;

public partial class Issue9978 : ContentPage
{
public Issue9978()
{
InitializeComponent();
}

public Issue9978(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}

[TestFixture]
public class Tests
{
[TestCase(false)]
[TestCase(true)]
public void OnIdiomReturnsBindableDefaultIfNotSet(bool useCompiledXaml)
{
var idioms = new[]
{
DeviceIdiom.Tablet,
DeviceIdiom.Phone,
DeviceIdiom.Desktop,
DeviceIdiom.Watch,
DeviceIdiom.TV
};

foreach (var idiom in idioms)
{
DeviceInfo.SetCurrent(new MockDeviceInfo { Idiom = idiom });
var page = new Issue9978(useCompiledXaml);

if (idiom == DeviceIdiom.Tablet)
{
Assert.AreEqual(50, page.mauiButton.HeightRequest, $"Expected 50 for idiom Tablet");
}
else
{
Assert.AreEqual(-1, page.mauiButton.HeightRequest, $"Expected -1 for idiom {idiom}");
}
}
}

}
}
1 change: 1 addition & 0 deletions src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ public void StackLayoutOrientation()
layout = new StackLayout().LoadFromXaml(xaml);
Assert.AreEqual(StackOrientation.Horizontal, layout.Orientation);
}

}
}