From f965634568671479bdee43a41ca0ba7f65ea89d7 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Sat, 12 Oct 2024 11:31:31 +0200 Subject: [PATCH] Fix ThemeVariant equality (#17257) * Added failing ThemeVariant theme * Fixed ThemeVariant.Equals --- src/Avalonia.Base/Styling/ThemeVariant.cs | 2 +- .../Xaml/ThemeDictionariesTests.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Styling/ThemeVariant.cs b/src/Avalonia.Base/Styling/ThemeVariant.cs index 23bc15dfa79..ac44fddb994 100644 --- a/src/Avalonia.Base/Styling/ThemeVariant.cs +++ b/src/Avalonia.Base/Styling/ThemeVariant.cs @@ -91,7 +91,7 @@ public override int GetHashCode() public bool Equals(ThemeVariant? other) { - return Key == other?.Key; + return other is not null && Equals(Key, other.Key); } public static explicit operator ThemeVariant(PlatformThemeVariant themeVariant) diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ThemeDictionariesTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ThemeDictionariesTests.cs index 1160e8d9c5d..189aa600a58 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ThemeDictionariesTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ThemeDictionariesTests.cs @@ -45,7 +45,8 @@ public void DynamicResource_Updated_When_Control_Theme_Changed() Assert.Equal(Colors.White, ((ISolidColorBrush)border.Background)!.Color); - themeVariantScope.RequestedThemeVariant = ThemeVariant.Dark; + var themeVariantKey = new string(['D', 'a', 'r', 'k']); // Ensure that a non-interned string works + themeVariantScope.RequestedThemeVariant = new ThemeVariant(themeVariantKey, null); Assert.Equal(Colors.Black, ((ISolidColorBrush)border.Background)!.Color); }