annotate Workflow/Client/Controls/UIMessage.xaml.cs @ 101:2372846797f0

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