diff --git a/src/Controls/src/Xaml/MarkupExtensions/OnIdiomExtension.cs b/src/Controls/src/Xaml/MarkupExtensions/OnIdiomExtension.cs
index c92eef52a5c7..93a7946d8212 100644
--- a/src/Controls/src/Xaml/MarkupExtensions/OnIdiomExtension.cs
+++ b/src/Controls/src/Xaml/MarkupExtensions/OnIdiomExtension.cs
@@ -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);
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml
new file mode 100644
index 000000000000..21cbb9fd3959
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml.cs
new file mode 100644
index 000000000000..c05b9f7a0376
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue9978.xaml.cs
@@ -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
+{
+ public Issue9978()
+ {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9978.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9978.cs
new file mode 100644
index 000000000000..515bc86d1556
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9978.cs
@@ -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");
+
+ }
+}
diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml
new file mode 100644
index 000000000000..6e62c200dfc8
--- /dev/null
+++ b/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml.cs
new file mode 100644
index 000000000000..359641780272
--- /dev/null
+++ b/src/Controls/tests/Xaml.UnitTests/Issues/Issue9978.xaml.cs
@@ -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}");
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs b/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs
index c6a47525e1b9..7fc8d62c0c57 100644
--- a/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs
+++ b/src/Controls/tests/Xaml.UnitTests/OnPlatformTests.cs
@@ -178,5 +178,6 @@ public void StackLayoutOrientation()
layout = new StackLayout().LoadFromXaml(xaml);
Assert.AreEqual(StackOrientation.Horizontal, layout.Orientation);
}
+
}
}
\ No newline at end of file