Skip to content

Instantly share code, notes, and snippets.

@binaryfunt
Created August 1, 2018 10:37
Show Gist options
  • Save binaryfunt/109888e6587615b07c1ac711f17773b2 to your computer and use it in GitHub Desktop.
Save binaryfunt/109888e6587615b07c1ac711f17773b2 to your computer and use it in GitHub Desktop.
JavaScript-style Alert() function implemented in Windows UWP
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