Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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");

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

[Test]
public void OnIdiomReturnsBindablePropertyDefaultWhenNotSet()

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.

look at what other tests are doing, in the Issues folder. it needs a xaml and a xaml.cs file. this doesn't test XamlC inflation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sorry about that — I hadn’t opened Xaml.UnitTests until a few hours ago. :)

{
var xaml = @"
<Button
xmlns=""http://schemas.microsoft.com/dotnet/2021/maui""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
Text=""Sample Button""
HeightRequest=""{OnIdiom Tablet=50}"" />";

mockDeviceInfo.Idiom = DeviceIdiom.Tablet;
var button = new Button().LoadFromXaml(xaml);
Assert.AreEqual(50, button.HeightRequest);

foreach (var idiom in new[] { DeviceIdiom.Phone, DeviceIdiom.Desktop, DeviceIdiom.TV, DeviceIdiom.Watch })
{
mockDeviceInfo.Idiom = idiom;
button = new Button().LoadFromXaml(xaml);
Assert.AreEqual(-1, button.HeightRequest, $"Expected default value -1 for idiom {idiom}");
}
}

}
}