diff --git a/src/Controls/src/Core/SolidColorBrush.cs b/src/Controls/src/Core/SolidColorBrush.cs
index 9429bf2b8812..ab4e1a59d957 100644
--- a/src/Controls/src/Core/SolidColorBrush.cs
+++ b/src/Controls/src/Core/SolidColorBrush.cs
@@ -47,7 +47,7 @@ public override bool Equals(object obj)
if (!(obj is SolidColorBrush dest))
return false;
- return Color == dest.Color;
+ return Equals(Color, dest.Color);
}
///
diff --git a/src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs b/src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs
index ee771f99ff09..5a7cb764f16a 100644
--- a/src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs
+++ b/src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs
@@ -53,5 +53,30 @@ public void TestDefaultBrushes()
Assert.NotNull(white.Color);
Assert.Equal(white.Color, Colors.White);
}
+
+ [Fact]
+ // https://github.com/dotnet/maui/issues/27281
+ public void SolidColorBrushEqualsComparesColorValues()
+ {
+ // Create two Color instances with identical RGBA values but different object references
+ // This simulates what happens with OnPlatform which creates new Color instances
+ var color1 = new Color(1.0f, 0.0f, 0.0f, 1.0f);
+ var color2 = new Color(1.0f, 0.0f, 0.0f, 1.0f);
+
+ // Verify these are different instances
+ Assert.False(ReferenceEquals(color1, color2));
+
+ // Verify the Color.Equals method returns true for same values
+ Assert.True(color1.Equals(color2));
+
+ // Create SolidColorBrush instances with these colors
+ var brush1 = new SolidColorBrush(color1);
+ var brush2 = new SolidColorBrush(color2);
+
+ // This is the bug from issue #27281: SolidColorBrush.Equals uses '==' for Color comparison
+ // which compares references instead of values, causing infinite loops with DynamicResource
+ // and OnPlatform because OnPlatform creates new Color instances each time
+ Assert.True(brush1.Equals(brush2));
+ }
}
}
\ No newline at end of file