@@ -771,22 +771,18 @@ private void ApplyPreviewBackground(Color? bgColor = null)
771
771
{
772
772
if ( bgColor == null ) return ;
773
773
774
- // Copy the existing WindowBorderStyle
774
+ // Create a new Style for the preview
775
775
var previewStyle = new Style ( typeof ( Border ) ) ;
776
- if ( Application . Current . Resources . Contains ( "WindowBorderStyle" ) )
776
+
777
+ // Get the original WindowBorderStyle
778
+ if ( Application . Current . Resources . Contains ( "WindowBorderStyle" ) &&
779
+ Application . Current . Resources [ "WindowBorderStyle" ] is Style originalStyle )
777
780
{
778
- if ( Application . Current . Resources [ "WindowBorderStyle" ] is Style originalStyle )
779
- {
780
- foreach ( var setter in originalStyle . Setters . OfType < Setter > ( ) )
781
- {
782
- previewStyle . Setters . Add ( new Setter ( setter . Property , setter . Value ) ) ;
783
- }
784
- }
781
+ // Copy the original style, including the base style if it exists
782
+ CopyStyle ( originalStyle , previewStyle ) ;
785
783
}
786
784
787
785
// Apply background color (remove transparency in color)
788
- // WPF does not allow the use of an acrylic brush within the window's internal area,
789
- // so transparency effects are not applied to the preview.
790
786
Color backgroundColor = Color . FromRgb ( bgColor . Value . R , bgColor . Value . G , bgColor . Value . B ) ;
791
787
previewStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( backgroundColor ) ) ) ;
792
788
@@ -797,9 +793,26 @@ private void ApplyPreviewBackground(Color? bgColor = null)
797
793
previewStyle . Setters . Add ( new Setter ( Border . CornerRadiusProperty , new CornerRadius ( 5 ) ) ) ;
798
794
previewStyle . Setters . Add ( new Setter ( Border . BorderThicknessProperty , new Thickness ( 1 ) ) ) ;
799
795
}
796
+
797
+ // Set the new style to the resource
800
798
Application . Current . Resources [ "PreviewWindowBorderStyle" ] = previewStyle ;
801
799
}
802
800
801
+ private void CopyStyle ( Style originalStyle , Style targetStyle )
802
+ {
803
+ // If the style is based on another style, copy the base style first
804
+ if ( originalStyle . BasedOn != null )
805
+ {
806
+ CopyStyle ( originalStyle . BasedOn , targetStyle ) ;
807
+ }
808
+
809
+ // Copy the setters from the original style
810
+ foreach ( var setter in originalStyle . Setters . OfType < Setter > ( ) )
811
+ {
812
+ targetStyle . Setters . Add ( new Setter ( setter . Property , setter . Value ) ) ;
813
+ }
814
+ }
815
+
803
816
private void ColorizeWindow ( string theme , BackdropTypes backdropType )
804
817
{
805
818
var dict = GetThemeResourceDictionary ( theme ) ;
0 commit comments