ContentDialogExtensions.cs 679 B

123456789101112131415161718192021222324252627282930
  1. namespace NatTypeTester.Extensions;
  2. internal static class ContentDialogExtensions
  3. {
  4. public static async ValueTask HandleExceptionWithContentDialogAsync(this Exception ex, XamlRoot root)
  5. {
  6. ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();
  7. ContentDialog dialog = new();
  8. try
  9. {
  10. dialog.XamlRoot = root;
  11. dialog.Title = nameof(NatTypeTester);
  12. string content = resourceLoader.GetString(ex.Message);
  13. if (string.IsNullOrEmpty(content))
  14. {
  15. content = ex.Message;
  16. }
  17. dialog.Content = content;
  18. dialog.PrimaryButtonText = resourceLoader.GetString(@"OK");
  19. await dialog.ShowAsync();
  20. }
  21. finally
  22. {
  23. dialog.Hide();
  24. }
  25. }
  26. }