1
1
using System . Windows . Media ;
2
+ using System . Windows . Media . Effects ;
2
3
3
4
namespace MaterialDesignThemes . Wpf ;
4
5
@@ -445,6 +446,31 @@ public CornerRadius? BottomDrawerCornerRadius
445
446
446
447
#endregion
447
448
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
+
448
474
#region open drawer events/callbacks
449
475
450
476
public static readonly RoutedEvent DrawerOpenedEvent =
@@ -593,7 +619,8 @@ private static void IsBottomDrawerOpenPropertyChangedCallback(DependencyObject d
593
619
private static void IsDrawerOpenPropertyChanged ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs , Dock dock )
594
620
{
595
621
var drawerHost = ( DrawerHost ) dependencyObject ;
596
- if ( ! ( bool ) dependencyPropertyChangedEventArgs . NewValue )
622
+ bool isOpened = ( bool ) dependencyPropertyChangedEventArgs . NewValue ;
623
+ if ( ! isOpened )
597
624
{
598
625
var args = new DrawerClosingEventArgs ( dock , DrawerClosingEvent ) ;
599
626
drawerHost . OnDrawerClosing ( args ) ;
@@ -604,16 +631,43 @@ private static void IsDrawerOpenPropertyChanged(DependencyObject dependencyObjec
604
631
}
605
632
}
606
633
607
- if ( ! drawerHost . _lockZIndexes && ( bool ) dependencyPropertyChangedEventArgs . NewValue )
634
+ if ( ! drawerHost . _lockZIndexes && isOpened )
608
635
drawerHost . PrepareZIndexes ( drawerHost . _zIndexPropertyLookup [ dependencyPropertyChangedEventArgs . Property ] ) ;
609
636
drawerHost . UpdateVisualStates ( ) ;
610
637
611
- if ( ( bool ) dependencyPropertyChangedEventArgs . NewValue )
638
+ drawerHost . HandleBackgroundBlur ( isOpened ) ;
639
+
640
+ if ( isOpened )
612
641
{
613
642
RaiseDrawerOpened ( drawerHost , dock ) ;
614
643
}
615
644
}
616
645
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
+
617
671
private static void RaiseDrawerOpened ( DrawerHost drawerHost , Dock dock )
618
672
{
619
673
//multiple ways of calling back that the drawer has opened:
0 commit comments