From 2c195c2632d1fadf8d0ef21e96135091a5098cfd Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 29 Jun 2019 21:54:15 -0700 Subject: [PATCH] add CloseOnBackgroundTapped property --- .../Prism.Forms/Services/Dialogs/DialogService.cs | 12 ++++++++++-- .../Services/Dialogs/Xaml/DialogLayout.cs | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Xamarin/Prism.Forms/Services/Dialogs/DialogService.cs b/Source/Xamarin/Prism.Forms/Services/Dialogs/DialogService.cs index 7a716b83f..a0d25d08c 100644 --- a/Source/Xamarin/Prism.Forms/Services/Dialogs/DialogService.cs +++ b/Source/Xamarin/Prism.Forms/Services/Dialogs/DialogService.cs @@ -70,8 +70,16 @@ void DialogAware_RequestClose(IDialogParameters outParameters) } } - parameters.TryGetValue(KnownDialogParameters.CloseOnBackgroundTapped, out var hideOnBackgroundTapped); - InsertPopupViewInCurrentPage(currentPage as ContentPage, view, hideOnBackgroundTapped, DialogAware_RequestClose); + if(!parameters.TryGetValue(KnownDialogParameters.CloseOnBackgroundTapped, out var closeOnBackgroundTapped)) + { + var dialogLayoutCloseOnBackgroundTapped = DialogLayout.GetCloseOnBackgroundTapped(view); + if(dialogLayoutCloseOnBackgroundTapped.HasValue) + { + closeOnBackgroundTapped = dialogLayoutCloseOnBackgroundTapped.Value; + } + } + + InsertPopupViewInCurrentPage(currentPage as ContentPage, view, closeOnBackgroundTapped, DialogAware_RequestClose); PageUtilities.InvokeViewAndViewModelAction(currentPage, aa => aa.IsActive = false); PageUtilities.InvokeViewAndViewModelAction(view, aa => aa.IsActive = true); diff --git a/Source/Xamarin/Prism.Forms/Services/Dialogs/Xaml/DialogLayout.cs b/Source/Xamarin/Prism.Forms/Services/Dialogs/Xaml/DialogLayout.cs index fe24a6054..6288effb0 100644 --- a/Source/Xamarin/Prism.Forms/Services/Dialogs/Xaml/DialogLayout.cs +++ b/Source/Xamarin/Prism.Forms/Services/Dialogs/Xaml/DialogLayout.cs @@ -52,5 +52,13 @@ public static class DialogLayout public static void SetMask(BindableObject bindable, View value) => bindable.SetValue(MaskProperty, value); + public static readonly BindableProperty CloseOnBackgroundTappedProperty = + BindableProperty.CreateAttached("CloseOnBackgroundTapped", typeof(bool?), typeof(DialogLayout), null); + + public static bool? GetCloseOnBackgroundTapped(BindableObject bindable) => + (bool?)bindable.GetValue(CloseOnBackgroundTappedProperty); + + public static void SetCloseOnBackgroundTapped(BindableObject bindable, bool? value) => + bindable.SetValue(CloseOnBackgroundTappedProperty, value); } }