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.
This commit is contained in:
Jack251970 2026-03-09 18:54:10 +08:00
parent 2bf6e2634c
commit 3c82661262
2 changed files with 15 additions and 7 deletions

View file

@ -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<Setter>().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<Setter>().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.

View file

@ -21,6 +21,15 @@ public static class ThemeHelper
}
}
public static void ReplaceSetter(Style style, Setter setter)
{
var existingSetter = style.Setters.OfType<Setter>().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);