@@ -416,21 +416,24 @@ private static void SetResizeBoarderThickness(Thickness? effectMargin)
416416 /// </summary>
417417 public async Task RefreshFrameAsync ( )
418418 {
419- await Application . Current . Dispatcher . InvokeAsync ( async ( ) =>
419+ await Application . Current . Dispatcher . InvokeAsync ( ( ) =>
420420 {
421+ // Get the actual backdrop type and drop shadow effect settings
422+ var ( backdropType , useDropShadowEffect ) = GetActualValue ( ) ;
423+
421424 // Remove OS minimizing/maximizing animation
422425 // Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3);
423-
426+
424427 // The timing of adding the shadow effect should vary depending on whether the theme is transparent.
425428 if ( BlurEnabled )
426429 {
427- AutoDropShadow ( ) ;
430+ AutoDropShadow ( useDropShadowEffect ) ;
428431 }
429- await SetBlurForWindowAsync ( ) ;
432+ SetBlurForWindow ( backdropType ) ;
430433
431434 if ( ! BlurEnabled )
432435 {
433- AutoDropShadow ( ) ;
436+ AutoDropShadow ( useDropShadowEffect ) ;
434437 }
435438 } , DispatcherPriority . Normal ) ;
436439 }
@@ -440,61 +443,87 @@ await Application.Current.Dispatcher.InvokeAsync(async () =>
440443 /// </summary>
441444 public async Task SetBlurForWindowAsync ( )
442445 {
443- await Application . Current . Dispatcher . InvokeAsync ( async ( ) =>
446+ await Application . Current . Dispatcher . InvokeAsync ( ( ) =>
444447 {
445- var dict = GetThemeResourceDictionary ( _settings . Theme ) ;
446- if ( dict == null )
447- return ;
448+ // Get the actual backdrop type and drop shadow effect settings
449+ var ( backdropType , _) = GetActualValue ( ) ;
448450
449- var windowBorderStyle = dict . Contains ( "WindowBorderStyle" ) ? dict [ "WindowBorderStyle" ] as Style : null ;
450- if ( windowBorderStyle == null )
451- return ;
451+ SetBlurForWindow ( backdropType ) ;
452+ } , DispatcherPriority . Normal ) ;
453+ }
452454
453- Window mainWindow = Application . Current . MainWindow ;
454- if ( mainWindow == null )
455- return ;
455+ /// <summary>
456+ /// Gets the actual backdrop type and drop shadow effect settings based on the current theme status.
457+ /// </summary>
458+ public ( BackdropTypes BackdropType , bool UseDropShadowEffect ) GetActualValue ( )
459+ {
460+ var backdropType = _settings . BackdropType ;
461+ var useDropShadowEffect = _settings . UseDropShadowEffect ;
456462
457- // Check if the theme supports blur
458- bool hasBlur = dict . Contains ( "ThemeBlurEnabled" ) && dict [ "ThemeBlurEnabled" ] is bool b && b ;
459- if ( ! hasBlur )
460- {
461- _settings . BackdropType = BackdropTypes . None ;
462- }
463+ // When changed non-blur theme, change to backdrop to none
464+ if ( ! BlurEnabled )
465+ {
466+ backdropType = BackdropTypes . None ;
467+ }
463468
464- if ( BlurEnabled && hasBlur && Win32Helper . IsBackdropSupported ( ) )
465- {
466- // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
467- if ( _settings . BackdropType == BackdropTypes . Mica || _settings . BackdropType == BackdropTypes . MicaAlt )
468- {
469- windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
470- windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ) ) ;
471- }
472- else if ( _settings . BackdropType == BackdropTypes . Acrylic )
473- {
474- windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
475- windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Colors . Transparent ) ) ) ;
476- }
469+ // Dropshadow on and control disabled.(user can't change dropshadow with blur theme)
470+ if ( BlurEnabled )
471+ {
472+ useDropShadowEffect = true ;
473+ }
477474
478- // Apply the blur effect
479- Win32Helper . DWMSetBackdropForWindow ( mainWindow , _settings . BackdropType ) ;
480- ColorizeWindow ( ) ;
475+ return ( backdropType , useDropShadowEffect ) ;
476+ }
477+
478+ private void SetBlurForWindow ( BackdropTypes backdropType )
479+ {
480+ var dict = GetThemeResourceDictionary ( _settings . Theme ) ;
481+ if ( dict == null )
482+ return ;
483+
484+ var windowBorderStyle = dict . Contains ( "WindowBorderStyle" ) ? dict [ "WindowBorderStyle" ] as Style : null ;
485+ if ( windowBorderStyle == null )
486+ return ;
487+
488+ Window mainWindow = Application . Current . MainWindow ;
489+ if ( mainWindow == null )
490+ return ;
491+
492+ // Check if the theme supports blur
493+ bool hasBlur = dict . Contains ( "ThemeBlurEnabled" ) && dict [ "ThemeBlurEnabled" ] is bool b && b ;
494+ if ( BlurEnabled && hasBlur && Win32Helper . IsBackdropSupported ( ) )
495+ {
496+ // If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
497+ if ( backdropType == BackdropTypes . Mica || backdropType == BackdropTypes . MicaAlt )
498+ {
499+ windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
500+ windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ) ) ;
481501 }
482- else
502+ else if ( backdropType == BackdropTypes . Acrylic )
483503 {
484- // Apply default style when Blur is disabled
485- Win32Helper . DWMSetBackdropForWindow ( mainWindow , BackdropTypes . None ) ;
486- ColorizeWindow ( ) ;
504+ windowBorderStyle . Setters . Remove ( windowBorderStyle . Setters . OfType < Setter > ( ) . FirstOrDefault ( x => x . Property . Name == "Background" ) ) ;
505+ windowBorderStyle . Setters . Add ( new Setter ( Border . BackgroundProperty , new SolidColorBrush ( Colors . Transparent ) ) ) ;
487506 }
488507
489- UpdateResourceDictionary ( dict ) ;
490- } , DispatcherPriority . Normal ) ;
508+ // Apply the blur effect
509+ Win32Helper . DWMSetBackdropForWindow ( mainWindow , backdropType ) ;
510+ ColorizeWindow ( backdropType ) ;
511+ }
512+ else
513+ {
514+ // Apply default style when Blur is disabled
515+ Win32Helper . DWMSetBackdropForWindow ( mainWindow , BackdropTypes . None ) ;
516+ ColorizeWindow ( backdropType ) ;
517+ }
518+
519+ UpdateResourceDictionary ( dict ) ;
491520 }
492521
493- private void AutoDropShadow ( )
522+ private void AutoDropShadow ( bool useDropShadowEffect )
494523 {
495524 SetWindowCornerPreference ( "Default" ) ;
496525 RemoveDropShadowEffectFromCurrentTheme ( ) ;
497- if ( _settings . UseDropShadowEffect )
526+ if ( useDropShadowEffect )
498527 {
499528 if ( BlurEnabled && Win32Helper . IsBackdropSupported ( ) )
500529 {
@@ -605,7 +634,7 @@ private void ApplyPreviewBackground(Color? bgColor = null)
605634 Application . Current . Resources [ "PreviewWindowBorderStyle" ] = previewStyle ;
606635 }
607636
608- private void ColorizeWindow ( )
637+ private void ColorizeWindow ( BackdropTypes backdropType )
609638 {
610639 var dict = GetThemeResourceDictionary ( _settings . Theme ) ;
611640 if ( dict == null ) return ;
@@ -688,7 +717,7 @@ private void ColorizeWindow()
688717 else
689718 {
690719 // Only set the background to transparent if the theme supports blur
691- if ( _settings . BackdropType == BackdropTypes . Mica || _settings . BackdropType == BackdropTypes . MicaAlt )
720+ if ( backdropType == BackdropTypes . Mica || backdropType == BackdropTypes . MicaAlt )
692721 {
693722 mainWindow . Background = new SolidColorBrush ( Color . FromArgb ( 1 , 0 , 0 , 0 ) ) ;
694723 }
0 commit comments