From 3c8266126268f4e0aa6144cbcb6f331d6412bfb8 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 9 Mar 2026 18:54:10 +0800 Subject: [PATCH] Remove duplicate Margin and Effect setters in theme code Ensure existing Margin and Effect setters are removed from newWindowBorderStyle before adding new ones. This prevents duplicate property setters and ensures only the latest values are applied. --- Flow.Launcher.Core/Resource/Theme.cs | 13 ++++++------- Flow.Launcher.Core/Resource/ThemeHelper.cs | 9 +++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 669628fd9..a32a59b48 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -525,10 +525,10 @@ namespace Flow.Launcher.Core.Resource } // Add new Margin Setter - newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, newMargin)); + ThemeHelper.ReplaceSetter(newWindowBorderStyle, new Setter(FrameworkElement.MarginProperty, newMargin)); // Add Drop Shadow Effect Setter - newWindowBorderStyle.Setters.Add(new Setter + ThemeHelper.ReplaceSetter(newWindowBorderStyle, new Setter { Property = UIElement.EffectProperty, Value = new DropShadowEffect @@ -574,10 +574,11 @@ namespace Flow.Launcher.Core.Resource currentMargin.Top - ShadowExtraMargin, currentMargin.Right - ShadowExtraMargin, currentMargin.Bottom - ShadowExtraMargin); - newWindowBorderStyle.Setters.Add(new Setter(FrameworkElement.MarginProperty, newMargin)); + ThemeHelper.ReplaceSetter(newWindowBorderStyle, new Setter(FrameworkElement.MarginProperty, newMargin)); continue; } } + newWindowBorderStyle.Setters.Add(setterBase); } @@ -710,13 +711,11 @@ namespace Flow.Launcher.Core.Resource // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent if (backdropType is BackdropTypes.Mica or BackdropTypes.MicaAlt) { - windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property == Control.BackgroundProperty)); - windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); + ThemeHelper.ReplaceSetter(windowBorderStyle, new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0)))); } else if (backdropType == BackdropTypes.Acrylic) { - windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property == Control.BackgroundProperty)); - windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, Brushes.Transparent)); + ThemeHelper.ReplaceSetter(windowBorderStyle, new Setter(Border.BackgroundProperty, Brushes.Transparent)); } // For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness. diff --git a/Flow.Launcher.Core/Resource/ThemeHelper.cs b/Flow.Launcher.Core/Resource/ThemeHelper.cs index bf89cdd1d..1be9c6ba4 100644 --- a/Flow.Launcher.Core/Resource/ThemeHelper.cs +++ b/Flow.Launcher.Core/Resource/ThemeHelper.cs @@ -21,6 +21,15 @@ public static class ThemeHelper } } + public static void ReplaceSetter(Style style, Setter setter) + { + var existingSetter = style.Setters.OfType().FirstOrDefault(s => s.Property == setter.Property); + if (existingSetter != null) + style.Setters.Remove(existingSetter); + + style.Setters.Add(setter); + } + public static SolidColorBrush GetFrozenSolidColorBrush(Color color) { var brush = new SolidColorBrush(color);