[UWP] Only display one alert at a time
This commit is contained in:
Коммит
88e8e0785b
|
@ -16,7 +16,7 @@ namespace Xamarin.Forms.Controls
|
|||
{
|
||||
protected override void Init()
|
||||
{
|
||||
var button = new Button { Text = "Click to call DisplayAlert twice" };
|
||||
var button = new Button { Text = "Click to call DisplayAlert three times" };
|
||||
|
||||
button.Clicked += (sender, args) =>
|
||||
{
|
||||
|
@ -29,6 +29,11 @@ namespace Xamarin.Forms.Controls
|
|||
{
|
||||
await DisplayAlert("Second", "Text", "Cancel");
|
||||
}));
|
||||
|
||||
Device.BeginInvokeOnMainThread(new Action(async () =>
|
||||
{
|
||||
await DisplayAlert("Three", "Text", "Cancel");
|
||||
}));
|
||||
};
|
||||
|
||||
Content = button;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
public abstract partial class Platform
|
||||
{
|
||||
internal static StatusBar MobileStatusBar => ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar") ? StatusBar.GetForCurrentView() : null;
|
||||
static Task<bool> s_currentAlert;
|
||||
|
||||
IToolbarProvider _toolbarProvider;
|
||||
|
||||
|
@ -102,12 +103,21 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
if (options.Accept != null)
|
||||
alertDialog.PrimaryButtonText = options.Accept;
|
||||
|
||||
ContentDialogResult result = await alertDialog.ShowAsync();
|
||||
while (s_currentAlert != null)
|
||||
{
|
||||
await s_currentAlert;
|
||||
}
|
||||
|
||||
if (result == ContentDialogResult.Secondary)
|
||||
options.SetResult(false);
|
||||
else if (result == ContentDialogResult.Primary)
|
||||
options.SetResult(true);
|
||||
s_currentAlert = ShowAlert(alertDialog);
|
||||
options.SetResult(await s_currentAlert);
|
||||
s_currentAlert = null;
|
||||
}
|
||||
|
||||
static async Task<bool> ShowAlert(ContentDialog alert)
|
||||
{
|
||||
ContentDialogResult result = await alert.ShowAsync();
|
||||
|
||||
return result == ContentDialogResult.Primary;
|
||||
}
|
||||
|
||||
void ClearCommandBar()
|
||||
|
|
Загрузка…
Ссылка в новой задаче