Created
August 1, 2018 10:37
-
-
Save binaryfunt/109888e6587615b07c1ac711f17773b2 to your computer and use it in GitHub Desktop.
JavaScript-style Alert() function implemented in Windows UWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed partial class App : Application | |
{ | |
... | |
private static List<ContentDialog> DialogQueue { get; } = new List<ContentDialog>(); | |
public static async void Alert(string text) | |
{ | |
var Dialog = new ContentDialog() | |
{ | |
Title = text, | |
CloseButtonText = "OK" | |
... | |
}; | |
App.DialogQueue.Add(Dialog); | |
// Add event handler for when dialog closed: | |
Dialog.Closed += Dialog_Closed; | |
if (App.DialogQueue.Count == 1) // Only one in queue | |
{ | |
await Dialog.ShowAsync(); | |
} | |
} | |
// Event handler for when dialog closed: | |
private static async void Dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) | |
{ | |
App.DialogQueue.Remove(sender); | |
if (App.DialogQueue.Count > 0) | |
{ | |
await App.DialogQueue[0].ShowAsync(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment