11using System . Windows . Media ;
2+ using System . Windows . Media . Effects ;
23
34namespace MaterialDesignThemes . Wpf ;
45
@@ -445,6 +446,31 @@ public CornerRadius? BottomDrawerCornerRadius
445446
446447 #endregion
447448
449+ #region Blur effect
450+ public bool ApplyBlurBackground
451+ {
452+ get => ( bool ) GetValue ( ApplyBlurBackgroundProperty ) ;
453+ set => SetValue ( ApplyBlurBackgroundProperty , value ) ;
454+ }
455+ public static readonly DependencyProperty ApplyBlurBackgroundProperty = DependencyProperty . Register (
456+ nameof ( ApplyBlurBackground ) , typeof ( bool ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( bool ) , OnBlurPropertyChanged ) ) ;
457+
458+ public const double DefaultBlurRadius = 16.0 ;
459+ public double BlurRadius
460+ {
461+ get => ( double ) GetValue ( BlurRadiusProperty ) ;
462+ set => SetValue ( BlurRadiusProperty , value ) ;
463+ }
464+ public static readonly DependencyProperty BlurRadiusProperty = DependencyProperty . Register (
465+ nameof ( BlurRadius ) , typeof ( double ) , typeof ( DrawerHost ) , new PropertyMetadata ( DefaultBlurRadius , OnBlurPropertyChanged ) ) ;
466+
467+ private static void OnBlurPropertyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
468+ {
469+ var drawerHost = ( DrawerHost ) d ;
470+ drawerHost . HandleBackgroundBlur ( ) ;
471+ }
472+ #endregion
473+
448474 #region open drawer events/callbacks
449475
450476 public static readonly RoutedEvent DrawerOpenedEvent =
@@ -593,7 +619,8 @@ private static void IsBottomDrawerOpenPropertyChangedCallback(DependencyObject d
593619 private static void IsDrawerOpenPropertyChanged ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs , Dock dock )
594620 {
595621 var drawerHost = ( DrawerHost ) dependencyObject ;
596- if ( ! ( bool ) dependencyPropertyChangedEventArgs . NewValue )
622+ bool isOpened = ( bool ) dependencyPropertyChangedEventArgs . NewValue ;
623+ if ( ! isOpened )
597624 {
598625 var args = new DrawerClosingEventArgs ( dock , DrawerClosingEvent ) ;
599626 drawerHost . OnDrawerClosing ( args ) ;
@@ -604,16 +631,43 @@ private static void IsDrawerOpenPropertyChanged(DependencyObject dependencyObjec
604631 }
605632 }
606633
607- if ( ! drawerHost . _lockZIndexes && ( bool ) dependencyPropertyChangedEventArgs . NewValue )
634+ if ( ! drawerHost . _lockZIndexes && isOpened )
608635 drawerHost . PrepareZIndexes ( drawerHost . _zIndexPropertyLookup [ dependencyPropertyChangedEventArgs . Property ] ) ;
609636 drawerHost . UpdateVisualStates ( ) ;
610637
611- if ( ( bool ) dependencyPropertyChangedEventArgs . NewValue )
638+ drawerHost . HandleBackgroundBlur ( isOpened ) ;
639+
640+ if ( isOpened )
612641 {
613642 RaiseDrawerOpened ( drawerHost , dock ) ;
614643 }
615644 }
616645
646+ private void HandleBackgroundBlur ( bool ? isOpened = null )
647+ {
648+ isOpened ??= IsAnyDrawerOpen ( ) ;
649+
650+ if ( Content is UIElement drawerContent )
651+ {
652+ if ( ApplyBlurBackground && isOpened . Value )
653+ {
654+ drawerContent . Effect = new BlurEffect ( )
655+ {
656+ Radius = BlurRadius
657+ } ;
658+ }
659+ else
660+ {
661+ drawerContent . Effect = null ;
662+ }
663+ }
664+
665+ bool IsAnyDrawerOpen ( )
666+ {
667+ return IsLeftDrawerOpen || IsTopDrawerOpen || IsRightDrawerOpen || IsBottomDrawerOpen ;
668+ }
669+ }
670+
617671 private static void RaiseDrawerOpened ( DrawerHost drawerHost , Dock dock )
618672 {
619673 //multiple ways of calling back that the drawer has opened:
0 commit comments