33using System . Windows . Data ;
44using System . Windows . Interop ;
55using System . Windows . Media ;
6+ using System . Windows . Media . Effects ;
67using System . Windows . Threading ;
78
89namespace MaterialDesignThemes . Wpf ;
@@ -15,11 +16,12 @@ public record DialogOptions
1516 internal double PreviousDialogContentUniformCornerRadius { get ; set ; }
1617 internal double PreviousPopupHeight { get ; set ; }
1718 internal double PreviousPopupWidth { get ; set ; }
18-
19+ internal bool PreviousApplyBlurEffect { get ; set ; }
20+ internal double PreviousBlurRadius { get ; set ; }
1921
2022 public static readonly DialogOptions Default = new ( ) ;
2123
22- // maybe in the future we should have a "OpeningEventHandler" if we already have a "ClosingEventHandler"?
24+ // if there is demand for it we could have a "OpeningEventHandler" too
2325 public DialogOpenedEventHandler ? OpenedEventHandler { get ; set ; } = null ;
2426 public DialogClosingEventHandler ? ClosingEventHandler { get ; set ; } = null ;
2527 public DialogClosedEventHandler ? ClosedEventHandler { get ; set ; } = null ;
@@ -29,8 +31,8 @@ public record DialogOptions
2931
3032 public bool CloseOnClickAway { get ; set ; } = false ;
3133
32- // public bool ApplyBlurEffect { get; set; } = false;
33- // public double BlurRadius { get; set; } = 16d;
34+ public bool ApplyBlurEffect { get ; set ; } = false ;
35+ public double BlurRadius { get ; set ; } = 16d ;
3436}
3537
3638/// <summary>
@@ -68,6 +70,7 @@ public class DialogHost : ContentControl
6870 public const string CloseButtonPartName = "PART_CloseButton" ;
6971 public const string OpenStateName = "Open" ;
7072 public const string ClosedStateName = "Closed" ;
73+ public const string ContentPresenterName = "ContentPresenter" ;
7174
7275 /// <summary>
7376 /// Routed command to be used somewhere inside an instance to trigger showing of the dialog. Content can be passed to the dialog via a <see cref="Button.CommandParameter"/>.
@@ -89,6 +92,7 @@ public class DialogHost : ContentControl
8992 private ContentControl ? _popupContentControl ;
9093 private Grid ? _contentCoverGrid ;
9194 private Button ? _closeButton ;
95+ private ContentPresenter ? _contentPresenter ;
9296 private DialogOpenedEventHandler ? _attachedDialogOpenedEventHandler ;
9397 private DialogClosingEventHandler ? _attachedDialogClosingEventHandler ;
9498 private DialogClosedEventHandler ? _attachedDialogClosedEventHandler ;
@@ -371,6 +375,17 @@ private void ApplyDialogOptions(DialogOptions options)
371375
372376 SetPopupSize ( ActualHeight , ActualWidth ) ;
373377 }
378+
379+ if ( options . ApplyBlurEffect && _contentPresenter is not null )
380+ {
381+ options . PreviousApplyBlurEffect = ApplyBlurBackground ;
382+ options . BlurRadius = BlurRadius ;
383+
384+ _contentPresenter . Effect = new BlurEffect ( )
385+ {
386+ Radius = options . BlurRadius
387+ } ;
388+ }
374389 }
375390
376391 private void RevertDialogOptions ( DialogOptions options )
@@ -399,6 +414,13 @@ private void RevertDialogOptions(DialogOptions options)
399414
400415 SetPopupSize ( options . PreviousPopupHeight , options . PreviousPopupWidth ) ;
401416 }
417+
418+ if ( options . ApplyBlurEffect && _contentPresenter is not null )
419+ {
420+ _contentPresenter . Effect = null ;
421+ ApplyBlurBackground = options . PreviousApplyBlurEffect ;
422+ BlurRadius = options . BlurRadius ;
423+ }
402424 }
403425
404426 internal async Task < object ? > ShowInternal ( object content , DialogOptions options )
@@ -796,6 +818,7 @@ public override void OnApplyTemplate()
796818 _popupContentControl = GetTemplateChild ( PopupContentPartName ) as ContentControl ;
797819 _contentCoverGrid = GetTemplateChild ( ContentCoverGridName ) as Grid ;
798820 _closeButton = GetTemplateChild ( CloseButtonPartName ) as Button ;
821+ _contentPresenter = GetTemplateChild ( ContentPresenterName ) as ContentPresenter ;
799822
800823 if ( _contentCoverGrid is not null )
801824 _contentCoverGrid . MouseLeftButtonUp += ContentCoverGridOnMouseLeftButtonUp ;
0 commit comments