1: public static class TransientMessageBox
2: {
3: const string MessageTextKey = "TransientMessageBoxText";
4: const string MessageCaptionKey = "TransientMessageBoxCaption";
5:
6: public static void ShowVirtual(string messageBoxText)
7: {
8: TransientStorageHelper.AddOrUpdate(MessageTextKey, messageBoxText);
9: }
10:
11: public static void ShowVirtual(string messageBoxText, string caption)
12: {
13: TransientStorageHelper.AddOrUpdate(MessageTextKey, messageBoxText);
14: TransientStorageHelper.AddOrUpdate(MessageCaptionKey, caption);
15: }
16:
17: public static void Show(string messageBoxText)
18: {
19: ShowVirtual(messageBoxText);
20:
21: var result = MessageBox.Show(messageBoxText);
22:
23: Debug.WriteLine("Transient MessageBox result:" + result);
24:
25: if (result == MessageBoxResult.OK)
26: {
27: RemoveTextKey();
28: }
29: }
30:
31: public static void Show(string messageBoxText, string caption)
32: {
33: ShowVirtual(messageBoxText, caption);
34:
35: var result = MessageBox.Show(messageBoxText, caption, MessageBoxButton.OK);
36:
37: Debug.WriteLine("Transient MessageBox result:" + result);
38:
39: if (result == MessageBoxResult.OK)
40: {
41: RemoveAllKeys();
42: }
43: }
44:
45: private static void RemoveAllKeys()
46: {
47: TransientStorageHelper.Remove(MessageTextKey);
48: TransientStorageHelper.Remove(MessageCaptionKey);
49: }
50:
51: private static void RemoveTextKey()
52: {
53: TransientStorageHelper.Remove(MessageTextKey);
54: }
55:
56: public static void ShowFromTransientValues()
57: {
58: if (!PhoneApplicationService.Current.State.ContainsKey(MessageTextKey)) return;
59:
60: if (PhoneApplicationService.Current.State.ContainsKey(MessageCaptionKey))
61: {
62: if (MessageBox.Show(TransientStorageHelper.GetValue<string>(MessageTextKey),
63: TransientStorageHelper.GetValue<string>(MessageCaptionKey),
64: MessageBoxButton.OK) == MessageBoxResult.OK)
65: {
66: RemoveAllKeys();
67: }
68: }
69: else
70: {
71: if (MessageBox.Show(TransientStorageHelper.GetValue<string>(MessageTextKey)) == MessageBoxResult.OK)
72: {
73: RemoveTextKey();
74: }
75: }
76: }
77: }