@@ -673,13 +673,17 @@ private void SetBlurForWindow(string theme, BackdropTypes backdropType)
673673 // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
674674 if ( backdropType == BackdropTypes . Mica || backdropType == BackdropTypes . MicaAlt )
675675 {
676- windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
677- windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ) ) ;
676+ windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property == Control . BackgroundProperty ) ) ;
677+ var brush = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
678+ brush . Freeze ( ) ;
679+ windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , brush ) ) ;
678680 }
679681 else if ( backdropType == BackdropTypes . Acrylic )
680682 {
681- windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
682- windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Colors . Transparent ) ) ) ;
683+ windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property == Control . BackgroundProperty ) ) ;
684+ var brush = new SolidColorBrush ( Colors . Transparent ) ;
685+ brush . Freeze ( ) ;
686+ windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , brush ) ) ;
683687 }
684688
685689 // For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness.
@@ -803,7 +807,9 @@ private void ApplyPreviewBackground(Color? bgColor = null)
803807
804808 // Apply background color (remove transparency in color)
805809 Color backgroundColor = Color . FromRgb ( bgColor . Value . R , bgColor . Value . G , bgColor . Value . B ) ;
806- previewStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( backgroundColor ) ) ) ;
810+ var brush = new SolidColorBrush ( backgroundColor ) ;
811+ brush . Freeze ( ) ;
812+ previewStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , brush ) ) ;
807813
808814 // The blur theme keeps the corner round fixed (applying DWM code to modify it causes rendering issues).
809815 // The non-blur theme retains the previously set WindowBorderStyle.
@@ -917,11 +923,15 @@ private void ColorizeWindow(string theme, BackdropTypes backdropType)
917923 // Only set the background to transparent if the theme supports blur
918924 if ( backdropType == BackdropTypes . Mica || backdropType == BackdropTypes . MicaAlt )
919925 {
920- mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
926+ var backgroundBrush = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
927+ backgroundBrush . Freeze ( ) ;
928+ mainWindow . Background = backgroundBrush ;
921929 }
922930 else
923931 {
924- mainWindow . Background = new SolidColorBrush ( selectedBG ) ;
932+ var backgroundBrush = new SolidColorBrush ( selectedBG ) ;
933+ backgroundBrush . Freeze ( ) ;
934+ mainWindow . Background = backgroundBrush ;
925935 }
926936 }
927937 }
0 commit comments