89
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
1 using System;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
2 using System.Windows;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
3 using System.Windows.Controls;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
4 using System.Windows.Media;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
5 using System.Windows.Media.Animation;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
6 using System.Windows.Media.Imaging;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
7
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
8 namespace Client.Controls
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
9 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
10 public enum MessageType
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
11 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
12 NotSet = 0,
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
13 Error,
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
14 Info,
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
15 Success,
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
16 Question
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
17 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
18
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
19 public partial class UIMessage : UserControl
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
20 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
21 #region Fields
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
22
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
23 private SolidColorBrush _errorBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
24 private SolidColorBrush _infoBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
25 private SolidColorBrush _successBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
26 private SolidColorBrush _questionBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
27
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
28 private BitmapImage _errorImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
29 private BitmapImage _infoImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
30 private BitmapImage _successImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
31 private BitmapImage _questionImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
32
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
33 private Storyboard _fadeInStoryboard;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
34 private Storyboard _fadeOutStoryboard;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
35
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
36 #endregion
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
37
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
38 #region Constructor
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
39
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
40 public UIMessage()
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
41 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
42 InitializeComponent();
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
43 CheckResourcesAreAvailable();
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
44
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
45 _fadeInStoryboard.Completed += (sender, args) => _fadeOutStoryboard.Begin();
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
46 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
47
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
48 #endregion
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
49
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
50 #region Dependency Properties: MessageType, Text
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
51
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
52 public static readonly DependencyProperty TypeProperty =
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
53 DependencyProperty.Register("MessageType",
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
54 typeof(MessageType),
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
55 typeof(UIMessage),
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
56 new PropertyMetadata(MessageType.NotSet, TypePropertyChanged));
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
57
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
58 private static void TypePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
59 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
60 var uiMessage = (UIMessage)dependencyObject;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
61 uiMessage.Display.SetValue(Border.BackgroundProperty, uiMessage.GetBrush(uiMessage.MessageType));
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
62 uiMessage.Icon.SetValue(Image.SourceProperty, uiMessage.GetImage(uiMessage.MessageType));
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
63 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
64
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
65 public MessageType MessageType
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
66 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
67 get { return (MessageType)GetValue(TypeProperty); }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
68 set { SetValue(TypeProperty, value); }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
69 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
70
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
71 public static readonly DependencyProperty TextProperty =
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
72 DependencyProperty.Register("Text",
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
73 typeof(string),
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
74 typeof(UIMessage),
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
75 new PropertyMetadata(default(string)));
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
76
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
77 public string Text
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
78 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
79 get { return (string)GetValue(TextProperty); }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
80 set { SetValue(TextProperty, value); }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
81 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
82
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
83 #endregion
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
84
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
85 #region Methods
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
86
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
87 private void CheckResourcesAreAvailable()
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
88 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
89 _errorBrush = (SolidColorBrush)this.Resources["ErrorBrush"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
90 _infoBrush = (SolidColorBrush)this.Resources["InfoBrush"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
91 _successBrush = (SolidColorBrush)this.Resources["SuccessBrush"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
92 _questionBrush = (SolidColorBrush)this.Resources["QuestionBrush"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
93 _errorImage = (BitmapImage)this.Resources["ErrorImage"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
94 _infoImage = (BitmapImage)this.Resources["InfoImage"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
95 _successImage = (BitmapImage)this.Resources["SuccessImage"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
96 _questionImage = (BitmapImage)this.Resources["QuestionImage"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
97 _fadeInStoryboard = (Storyboard)this.Resources["FadeIn"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
98 _fadeOutStoryboard = (Storyboard)this.Resources["FadeOut"];
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
99
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
100 if (_errorBrush == null) throw new Exception("Missing ErrorBrush resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
101 if (_infoBrush == null) throw new Exception("Missing InfoBrush resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
102 if (_successBrush == null) throw new Exception("Missing SuccessBrush resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
103 if (_questionBrush == null) throw new Exception("Missing QuestionBrush resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
104 if (_errorImage == null) throw new Exception("Missing BitmapImage ErrorImage resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
105 if (_infoImage == null) throw new Exception("Missing BitmapImage InfoImage resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
106 if (_successImage == null) throw new Exception("Missing BitmapImage SuccessImage resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
107 if (_questionImage == null) throw new Exception("Missing BitmapImage QuestionImage resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
108 if (_fadeInStoryboard == null) throw new Exception("Missing Storyboard FadeIn resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
109 if (_fadeOutStoryboard == null) throw new Exception("Missing Storyboard FadeOut resource");
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
110 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
111
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
112 private SolidColorBrush GetBrush(MessageType type)
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
113 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
114 SolidColorBrush brush = null;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
115 switch (type)
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
116 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
117 case MessageType.Info:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
118 brush = _infoBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
119 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
120 case MessageType.Error:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
121 brush = _errorBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
122 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
123 case MessageType.Success:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
124 brush = _successBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
125 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
126 case MessageType.Question:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
127 brush = _questionBrush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
128 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
129 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
130 return brush;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
131 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
132
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
133 private BitmapImage GetImage(MessageType type)
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
134 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
135 BitmapImage image = null;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
136 switch (type)
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
137 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
138 case MessageType.Info:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
139 image = _infoImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
140 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
141 case MessageType.Error:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
142 image = _errorImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
143 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
144 case MessageType.Success:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
145 image = _successImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
146 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
147 case MessageType.Question:
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
148 image = _questionImage;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
149 break;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
150 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
151 return image;
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
152 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
153
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
154 public void Show()
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
155 {
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
156 _fadeInStoryboard.Begin();
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
157 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
158
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
159 #endregion
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
160 }
|
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
161 } |