From 7005a685709a8f1527403628e478602f936374fb Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Wed, 25 Sep 2024 02:23:00 +0200 Subject: [PATCH] [C] fix specificity comparison (#24891) * test for #24849 * failing test * [C] OR EQUAL ! - fixes #24849 --- src/Controls/src/Core/Element/Element.cs | 2 +- .../AppResources/Style24849.xaml | 26 +++++++ .../AppResources/Style24849.xaml.cs | 16 +++++ .../Xaml.UnitTests/Issues/Maui24849.xaml | 7 ++ .../Xaml.UnitTests/Issues/Maui24849.xaml.cs | 71 +++++++++++++++++++ 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml create mode 100644 src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml.cs create mode 100644 src/Controls/tests/Xaml.UnitTests/Issues/Maui24849.xaml create mode 100644 src/Controls/tests/Xaml.UnitTests/Issues/Maui24849.xaml.cs diff --git a/src/Controls/src/Core/Element/Element.cs b/src/Controls/src/Core/Element/Element.cs index 8c3c13e013af..f8a193e6c3e1 100644 --- a/src/Controls/src/Core/Element/Element.cs +++ b/src/Controls/src/Core/Element/Element.cs @@ -747,7 +747,7 @@ internal void OnResourcesChanged(IEnumerable> value internal override void OnSetDynamicResource(BindableProperty property, string key, SetterSpecificity specificity) { base.OnSetDynamicResource(property, key, specificity); - if (!DynamicResources.TryGetValue(property, out var existing) || existing.Item2.CompareTo(specificity) < 0) + if (!DynamicResources.TryGetValue(property, out var existing) || existing.Item2.CompareTo(specificity) <= 0) DynamicResources[property] = (key, specificity); if (this.TryGetResource(key, out var value)) OnResourceChanged(property, value, specificity); diff --git a/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml b/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml new file mode 100644 index 000000000000..afab77d71927 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml @@ -0,0 +1,26 @@ + + + White + #3c3c3b + + \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml.cs b/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml.cs new file mode 100644 index 000000000000..e2be8a4d8adc --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/AppResources/Style24849.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Core.UnitTests; +using NUnit.Framework; + +namespace Microsoft.Maui.Controls.Xaml.UnitTests +{ + public partial class Style24849 : ResourceDictionary + { + public Style24849() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui24849.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Maui24849.xaml new file mode 100644 index 000000000000..d8e47a6bf560 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui24849.xaml @@ -0,0 +1,7 @@ + + +