@@ -771,22 +771,18 @@ private void ApplyPreviewBackground(Color? bgColor = null)
771771 {
772772 if ( bgColor == null ) return ;
773773
774- // Copy the existing WindowBorderStyle
774+ // Create a new Style for the preview
775775 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 )
777780 {
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 ) ;
785783 }
786784
787785 // 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.
790786 Color backgroundColor = Color . FromRgb ( bgColor . Value . R , bgColor . Value . G , bgColor . Value . B ) ;
791787 previewStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( backgroundColor ) ) ) ;
792788
@@ -797,9 +793,26 @@ private void ApplyPreviewBackground(Color? bgColor = null)
797793 previewStyle . Setters . Add ( new Setter ( Border . CornerRadiusProperty , new CornerRadius ( 5 ) ) ) ;
798794 previewStyle . Setters . Add ( new Setter ( Border . BorderThicknessProperty , new Thickness ( 1 ) ) ) ;
799795 }
796+
797+ // Set the new style to the resource
800798 Application . Current . Resources [ "PreviewWindowBorderStyle" ] = previewStyle ;
801799 }
802800
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+
803816 private void ColorizeWindow ( string theme , BackdropTypes backdropType )
804817 {
805818 var dict = GetThemeResourceDictionary ( theme ) ;
0 commit comments