Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ProcessWatchImpl/Scone/BiStateTextBox.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Fri Dec 11 17:21:35 2009 UTC (14 years, 3 months ago) by netseed
File size: 6860 byte(s)
作成途中

1 using System.Windows;
2 using System.Windows.Controls;
3 using System.Windows.Data;
4 using System.Windows.Media;
5 using debug = SeedCreate.CommonLibrary.DebugHelper;
6
7 namespace Toast.Scone
8 {
9
10
11
12
13 public
14 #if !DEBUG
15 abstract
16 #endif
17 class BiStateTextBox : TextBox
18 {
19 static BiStateTextBox()
20 {
21 // DefaultStyleKeyProperty.OverrideMetadata(typeof(UserIdBoxBase), new FrameworkPropertyMetadata(typeof(UserIdBoxBase)));
22 }
23
24 private BindingExpression expression_;
25
26
27 #if DEBUG
28 public
29 #else
30 protected
31 #endif
32 BiStateTextBox()
33 {
34 this.expression_ = null;
35 base.Loaded += new RoutedEventHandler(BiStateTextBox_Loaded);
36 }
37
38 void BiStateTextBox_Loaded(object sender, RoutedEventArgs e)
39 {
40 bool Recent = this.IsEmpty;
41
42 this.IsEmpty = false;
43 expression_ = this.GetBindingExpression(TextProperty);
44 this.IsEmpty = Recent;
45 }
46
47 #region Dependency Event
48
49 public static readonly RoutedEvent EmbodimentTextChangedEvent =
50 EventManager.RegisterRoutedEvent("EmbodimentTextChanged",
51 RoutingStrategy.Bubble, typeof(EmbodimentTextChangedEventHandler), typeof(BiStateTextBox));
52
53 public event EmbodimentTextChangedEventHandler EmbodimentTextChanged
54 {
55 add
56 {
57 AddHandler(EmbodimentTextChangedEvent, value);
58 }
59 remove
60 {
61 RemoveHandler(EmbodimentTextChangedEvent, value);
62 }
63 }
64
65 public static readonly RoutedEvent IsInvalidChangedEvent =
66 EventManager.RegisterRoutedEvent("IsInvalidChanged", RoutingStrategy.Bubble, typeof(BooleanPropertyChangedEventHandler),
67 typeof(BiStateTextBox));
68
69
70 public event BooleanPropertyChangedEventHandler IsInvalidChanged
71 {
72 add
73 {
74 AddHandler(IsInvalidChangedEvent, value);
75 }
76 remove
77 {
78 RemoveHandler(IsInvalidChangedEvent, value);
79 }
80 }
81
82 public static readonly RoutedEvent IsEmptyChangedEvent=
83 EventManager.RegisterRoutedEvent("IsEmptyChanged", RoutingStrategy.Bubble,
84 typeof(BooleanPropertyChangedEventHandler),
85 typeof(BiStateTextBox));
86
87 public event BooleanPropertyChangedEventHandler IsEmptyChanged
88 {
89 add
90 {
91 AddHandler(IsEmptyChangedEvent, value);
92 }
93 remove
94 {
95 RemoveHandler(IsEmptyChangedEvent, value);
96 }
97 }
98
99
100
101
102 #endregion
103
104 #region Dependency properties
105
106
107
108 #region EmbodimentText property
109
110 public static readonly DependencyProperty EmbodimentTextProperty
111 = DependencyProperty.Register("EmbodimentText", typeof(string), typeof(BiStateTextBox));
112
113 public string EmbodimentText
114 {
115 get
116 {
117 return (string)GetValue(EmbodimentTextProperty);
118 }
119 set
120 {
121 string Recent = EmbodimentText;
122 SetValue(EmbodimentTextProperty, value == null ? string.Empty : value);
123
124 EmbodimentTextChangedEventArgs e = new EmbodimentTextChangedEventArgs(EmbodimentTextChangedEvent, Recent, value);
125
126 if (value != null && value.Length != 0)
127 {
128 IsEmpty = false;
129 }
130 else
131 {
132 IsEmpty = true;
133 }
134 }
135 }
136
137 #endregion
138
139 #region EmptyExpressionProperty
140 public static readonly DependencyProperty EmptyExpressionProperty =
141 DependencyProperty.Register("EmptyExpression", typeof(string), typeof(BiStateTextBox));
142
143 public string EmptyExpression
144 {
145 get
146 {
147 return (string)GetValue(EmptyExpressionProperty);
148 }
149 set
150 {
151 SetValue(EmptyExpressionProperty, value);
152 }
153 }
154
155 #endregion
156
157
158 #region EmptyForeground property
159
160 public static readonly DependencyProperty EmptyForegroundProperty =
161 DependencyProperty.Register("EmptyForeground", typeof(Brush), typeof(BiStateTextBox));
162
163 public Brush EmptyForeground
164 {
165 get
166 {
167 return (Brush)GetValue(EmptyForegroundProperty);
168 }
169 set
170 {
171 SetValue(EmptyForegroundProperty, value);
172 }
173 }
174
175
176
177 #endregion
178
179 #region IsInvalid property
180
181 public static readonly DependencyProperty IsInvalidProperty
182 = DependencyProperty.Register("IsInvalid", typeof(bool), typeof(BiStateTextBox));
183
184 public bool IsInvalid
185 {
186 get
187 {
188 return (bool)GetValue(IsInvalidProperty);
189 }
190 set
191 {
192 bool Inspection = value != IsInvalid;
193
194 SetValue(IsInvalidProperty, value);
195
196 if (Inspection)
197 {
198 BooleanPropertyChangedEventArgs e = new BooleanPropertyChangedEventArgs(IsInvalidChangedEvent, value);
199 OnIsInvalidChanged(e);
200 }
201 }
202 }
203 #endregion
204
205 #region InvalidStateBackground property
206 public static readonly DependencyProperty InvalidStateBackgroundProperty
207 = DependencyProperty.Register("InvalidStateBackground", typeof(Brush), typeof(BiStateTextBox));
208
209 public Brush InvalidStateBackground
210 {
211 get
212 {
213 return (Brush)GetValue(InvalidStateBackgroundProperty);
214 }
215 set
216 {
217 SetValue(InvalidStateBackgroundProperty, value);
218 }
219 }
220
221
222 #endregion
223
224 #region IsEmpty property
225 public static readonly DependencyProperty IsEmptyProperty
226 = DependencyProperty.Register("IsEmpty", typeof(bool), typeof(BiStateTextBox),
227 new UIPropertyMetadata(true));
228
229 public bool IsEmpty
230 {
231 get
232 {
233 return (bool)GetValue(IsEmptyProperty);
234 }
235 #if !DEBUG
236 private
237 #endif
238 set
239 {
240 bool Inspection = value != IsEmpty;
241 SetValue(IsEmptyProperty, value);
242
243 if (Inspection)
244 {
245 OnIsEmptyChanged(new BooleanPropertyChangedEventArgs(IsEmptyChangedEvent, value));
246 }
247 }
248 }
249
250 public void CheckEmpty()
251 {
252 if (EmbodimentText.Length == 0)
253 {
254 IsEmpty = true;
255 }
256 else
257 {
258 IsEmpty = false;
259 }
260 }
261
262 #endregion
263 #endregion
264
265 protected override void OnGotFocus(RoutedEventArgs e)
266 {
267 this.IsEmpty = false;
268 base.OnGotFocus(e);
269 }
270
271 protected override void OnLostFocus(RoutedEventArgs e)
272 {
273 string Recent = this.EmbodimentText;
274
275 this.expression_.UpdateSource();
276
277 if (EmbodimentText != Recent)
278 {
279 OnEmbodimentTextChangedChanged(new EmbodimentTextChangedEventArgs(EmbodimentTextChangedEvent, EmbodimentText, Text));
280 }
281
282 this.IsInvalid = this.expression_.HasError;
283
284 if (Text.Length == 0)
285 {
286 this.IsEmpty = true;
287 }
288 else
289 {
290 this.IsEmpty = false;
291 }
292
293 base.OnLostFocus(e);
294 }
295
296 protected virtual void OnEmbodimentTextChangedChanged(EmbodimentTextChangedEventArgs e)
297 {
298 debug.TinyDebugWriter.WriteLine("Id is Changed\n\tRecent:{0}\n\tCurrent:{1}", e.Recent, e.Current);
299 RaiseEvent(e);
300 }
301
302 protected virtual void OnIsInvalidChanged(BooleanPropertyChangedEventArgs e)
303 {
304 debug.TinyDebugWriter.WriteLine("IsInvalid is changed:{0}", e.Current);
305 RaiseEvent(e);
306 }
307
308 protected virtual void OnIsEmptyChanged(BooleanPropertyChangedEventArgs e)
309 {
310 debug::TinyDebugWriter.WriteLine("IsEmpty is Changed:{0}", e.Current);
311 RaiseEvent(e);
312 }
313
314 }
315 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26