NotificationBox.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using System.IO.IsolatedStorage;
  13. using System.Windows.Controls.Primitives;
  14. using Microsoft.Phone.Controls;
  15. namespace WindowsPhone.Recipes.Push.Client.Controls
  16. {
  17. public partial class NotificationBox : UserControl
  18. {
  19. #region Fields
  20. private readonly IsolatedStorageSettings Settings = IsolatedStorageSettings.ApplicationSettings;
  21. private static Popup _popup;
  22. #endregion
  23. public string Title { get; set; }
  24. public string Message { get; set; }
  25. public bool ShowAgain
  26. {
  27. get
  28. {
  29. bool showAgain;
  30. if (!Settings.TryGetValue("NotificationBox.ShowAgain", out showAgain))
  31. {
  32. showAgain = true;
  33. ShowAgain = showAgain;
  34. }
  35. return showAgain;
  36. }
  37. set
  38. {
  39. Settings["NotificationBox.ShowAgain"] = value;
  40. }
  41. }
  42. private NotificationBox()
  43. {
  44. DataContext = this;
  45. InitializeComponent();
  46. }
  47. public static void Show(string title, string message)
  48. {
  49. if (_popup != null)
  50. {
  51. return;
  52. }
  53. var root = Application.Current.RootVisual as PhoneApplicationFrame;
  54. var notificationBox = new NotificationBox
  55. {
  56. Title = title,
  57. Message = message,
  58. Width = root.ActualWidth,
  59. MaxHeight = root.ActualHeight,
  60. HorizontalAlignment = HorizontalAlignment.Center,
  61. VerticalAlignment = VerticalAlignment.Center
  62. };
  63. if (!notificationBox.ShowAgain)
  64. return;
  65. _popup = new Popup
  66. {
  67. Child = notificationBox,
  68. IsOpen = true,
  69. };
  70. }
  71. private void buttonOk_Click(object sender, RoutedEventArgs e)
  72. {
  73. _popup.IsOpen = false;
  74. _popup = null;
  75. }
  76. }
  77. }