diff --git a/src/Controls/src/Core/SetterSpecificity.cs b/src/Controls/src/Core/SetterSpecificity.cs index 504f022381e3..b4c1a7cb8cd0 100644 --- a/src/Controls/src/Core/SetterSpecificity.cs +++ b/src/Controls/src/Core/SetterSpecificity.cs @@ -66,6 +66,10 @@ public SetterSpecificity(int style, int id, int @class, int type) : this(0, 0, 0 public int CompareTo(SetterSpecificity other) { + //VSM setters somehow supersedes Styles + if (Vsm != other.Vsm) + return Vsm.CompareTo(other.Vsm); + //everything coming from Style has lower priority than something that does not if (Style != other.Style && Style == 0) return 1; @@ -74,8 +78,6 @@ public int CompareTo(SetterSpecificity other) if (Style != other.Style) return Style.CompareTo(other.Style); - if (Vsm != other.Vsm) - return Vsm.CompareTo(other.Vsm); if (Manual != other.Manual) return Manual.CompareTo(other.Manual); if (DynamicResource != other.DynamicResource) diff --git a/src/Controls/src/Core/VisualStateManager.cs b/src/Controls/src/Core/VisualStateManager.cs index 2f4b1cfc8351..4fb62bd4f22d 100644 --- a/src/Controls/src/Core/VisualStateManager.cs +++ b/src/Controls/src/Core/VisualStateManager.cs @@ -72,6 +72,8 @@ public static bool GoToState(VisualElement visualElement, string name) var groups = (VisualStateGroupList)visualElement.GetValue(VisualStateGroupsProperty); var context = visualElement.GetContext(VisualStateGroupsProperty); var vsgSpecificity = context.Values.Keys.Last(); + if (vsgSpecificity == SetterSpecificity.DefaultValue) + vsgSpecificity = new SetterSpecificity(); groups.Specificity = vsgSpecificity; var specificity = new SetterSpecificity(1, 0, 0, 0, vsgSpecificity.Style, vsgSpecificity.Id, vsgSpecificity.Class, vsgSpecificity.Type); diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml b/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml new file mode 100644 index 000000000000..bf5bc9d02e51 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml.cs b/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml.cs new file mode 100644 index 000000000000..144540dbd381 --- /dev/null +++ b/src/Controls/tests/Xaml.UnitTests/Issues/Maui11204.xaml.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Controls.Core.UnitTests; +using Microsoft.Maui.Graphics; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Platform; +using NUnit.Framework; + + +namespace Microsoft.Maui.Controls.Xaml.UnitTests +{ + public partial class Maui11204 : ContentPage + { + public Maui11204() => InitializeComponent(); + public Maui11204(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] public void Setup() => AppInfo.SetCurrent(new MockAppInfo()); + [TearDown] public void TearDown() => AppInfo.SetCurrent(null); + + [Test] + public void VSMSetterOverrideManualValues([Values(false, true)] bool useCompiledXaml) + { + var page = new Maui11204(useCompiledXaml); + Assert.AreEqual(Colors.FloralWhite, page.border.BackgroundColor); + VisualStateManager.GoToState(page.border, "State1"); + Assert.AreEqual(2, page.border.StrokeThickness); + Assert.AreEqual(Colors.Blue, page.border.BackgroundColor); + } + + [Test] + public void StyleVSMSetterOverrideManualValues([Values(false, true)] bool useCompiledXaml) + { + var page = new Maui11204(useCompiledXaml); + Assert.AreEqual(Colors.HotPink, page.borderWithStyleClass.BackgroundColor); + VisualStateManager.GoToState(page.borderWithStyleClass, "State1"); + Assert.AreEqual(2, page.borderWithStyleClass.StrokeThickness); + Assert.AreEqual(Colors.Blue, page.borderWithStyleClass.BackgroundColor); + } + } + } +} \ No newline at end of file