From 3d96a368ffcadf7a58a079e8c18ac9f97e670f17 Mon Sep 17 00:00:00 2001 From: DB P Date: Sun, 13 Apr 2025 14:20:57 +0900 Subject: [PATCH] Fix Preview CornerRadius (Get BasedOn Style) --- Flow.Launcher.Core/Resource/Theme.cs | 35 +++++++++++++++++++--------- Flow.Launcher/SettingWindow.xaml | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 26fbfb1b4..3276854ed 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -771,22 +771,18 @@ namespace Flow.Launcher.Core.Resource { if (bgColor == null) return; - // Copy the existing WindowBorderStyle + // Create a new Style for the preview var previewStyle = new Style(typeof(Border)); - if (Application.Current.Resources.Contains("WindowBorderStyle")) + + // Get the original WindowBorderStyle + if (Application.Current.Resources.Contains("WindowBorderStyle") && + Application.Current.Resources["WindowBorderStyle"] is Style originalStyle) { - if (Application.Current.Resources["WindowBorderStyle"] is Style originalStyle) - { - foreach (var setter in originalStyle.Setters.OfType()) - { - previewStyle.Setters.Add(new Setter(setter.Property, setter.Value)); - } - } + // Copy the original style, including the base style if it exists + CopyStyle(originalStyle, previewStyle); } // Apply background color (remove transparency in color) - // WPF does not allow the use of an acrylic brush within the window's internal area, - // so transparency effects are not applied to the preview. Color backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B); previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(backgroundColor))); @@ -797,9 +793,26 @@ namespace Flow.Launcher.Core.Resource previewStyle.Setters.Add(new Setter(Border.CornerRadiusProperty, new CornerRadius(5))); previewStyle.Setters.Add(new Setter(Border.BorderThicknessProperty, new Thickness(1))); } + + // Set the new style to the resource Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle; } + private void CopyStyle(Style originalStyle, Style targetStyle) + { + // If the style is based on another style, copy the base style first + if (originalStyle.BasedOn != null) + { + CopyStyle(originalStyle.BasedOn, targetStyle); + } + + // Copy the setters from the original style + foreach (var setter in originalStyle.Setters.OfType()) + { + targetStyle.Setters.Add(new Setter(setter.Property, setter.Value)); + } + } + private void ColorizeWindow(string theme, BackdropTypes backdropType) { var dict = GetThemeResourceDictionary(theme); diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 6d629de63..ab27b235a 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -19,9 +19,9 @@ MouseDown="window_MouseDown" ResizeMode="CanResize" SnapsToDevicePixels="True" - UseLayoutRounding="True" StateChanged="Window_StateChanged" Top="{Binding SettingWindowTop, Mode=TwoWay}" + UseLayoutRounding="True" WindowStartupLocation="Manual" mc:Ignorable="d">