diff --git a/src/Forms/Prism.Forms/Common/ApplicationProvider.cs b/src/Forms/Prism.Forms/Common/ApplicationProvider.cs
index a33860f2a6..356fbc84d3 100644
--- a/src/Forms/Prism.Forms/Common/ApplicationProvider.cs
+++ b/src/Forms/Prism.Forms/Common/ApplicationProvider.cs
@@ -10,7 +10,7 @@ public class ApplicationProvider : IApplicationProvider
///
public Page MainPage
{
- get { return Application.Current.MainPage; }
+ get { return Application.Current?.MainPage; }
set { Application.Current.MainPage = value; }
}
}
diff --git a/src/Forms/Prism.Forms/Services/PageDialogService/IPageDialogService.cs b/src/Forms/Prism.Forms/Services/PageDialogService/IPageDialogService.cs
index 3656cbcecb..6ec4093171 100644
--- a/src/Forms/Prism.Forms/Services/PageDialogService/IPageDialogService.cs
+++ b/src/Forms/Prism.Forms/Services/PageDialogService/IPageDialogService.cs
@@ -8,6 +8,12 @@ namespace Prism.Services
///
public interface IPageDialogService
{
+ ///
+ /// Determines if the dialog can be shown.
+ ///
+ /// True if you can show the dialog; False if the dialog cannot be shown
+ bool CanShowDialog();
+
///
/// Presents an alert dialog to the application user with an accept and a cancel button.
///
diff --git a/src/Forms/Prism.Forms/Services/PageDialogService/PageDialogService.cs b/src/Forms/Prism.Forms/Services/PageDialogService/PageDialogService.cs
index b84243276e..617c4b2654 100644
--- a/src/Forms/Prism.Forms/Services/PageDialogService/PageDialogService.cs
+++ b/src/Forms/Prism.Forms/Services/PageDialogService/PageDialogService.cs
@@ -185,5 +185,14 @@ public virtual Task DisplayPromptAsync(string title, string message, str
var keyboard = _keyboardMapper.Map(keyboardType);
return _applicationProvider.MainPage.DisplayPromptAsync(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue);
}
+
+ ///
+ /// Determines if the dialog can be shown.
+ ///
+ /// True if you can show the dialog; False if the dialog cannot be shown
+ public bool CanShowDialog()
+ {
+ return _applicationProvider.MainPage != null;
+ }
}
}