markus / MarkupToPDF / Controls / Etc / DateControl.cs @ 90e7968d
이력 | 보기 | 이력해설 | 다운로드 (17.6 KB)
1 | 787a4489 | KangIngu | using System; |
---|---|---|---|
2 | using System.Net; |
||
3 | using System.Windows; |
||
4 | using System.Windows.Controls; |
||
5 | using System.Windows.Documents; |
||
6 | using System.Windows.Ink; |
||
7 | using System.Windows.Input; |
||
8 | using System.Windows.Media; |
||
9 | using System.Windows.Media.Animation; |
||
10 | using System.Windows.Shapes; |
||
11 | using System.ComponentModel; |
||
12 | using System.Collections.Generic; |
||
13 | using MarkupToPDF.Controls.Common; |
||
14 | using MarkupToPDF.Common; |
||
15 | |||
16 | namespace MarkupToPDF.Controls.Etc |
||
17 | { |
||
18 | public class DateControl : CommentUserInfo, IDisposable, IPath, INotifyPropertyChanged, IViewBox, IMarkupCommonData |
||
19 | { |
||
20 | private const string PART_ViewBox = "PART_ViewBox"; |
||
21 | private const string PART_TextBox = "PART_TextBox"; |
||
22 | public Viewbox Base_ViewBox = null; |
||
23 | public TextBlock Base_TextBox = null; |
||
24 | |||
25 | static DateControl() |
||
26 | { |
||
27 | DefaultStyleKeyProperty.OverrideMetadata(typeof(DateControl), new FrameworkPropertyMetadata(typeof(DateControl))); |
||
28 | //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
||
29 | ResourceDictionary dictionary = new ResourceDictionary(); |
||
30 | dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
31 | Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
32 | System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
||
33 | } |
||
34 | |||
35 | public DateControl() |
||
36 | { |
||
37 | this.DefaultStyleKey = typeof(DateControl); |
||
38 | } |
||
39 | |||
40 | |||
41 | #region Dependency Properties |
||
42 | |||
43 | |||
44 | public static readonly DependencyProperty IsSelectedProperty = |
||
45 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(DateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
46 | |||
47 | public static readonly DependencyProperty ControlTypeProperty = |
||
48 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(DateControl), new FrameworkPropertyMetadata(ControlType.Date)); |
||
49 | |||
50 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
51 | "OverViewPathData", typeof(Geometry), typeof(DateControl), null); |
||
52 | |||
53 | public static readonly DependencyProperty OverViewStartPointProperty = DependencyProperty.Register( |
||
54 | "OverViewStartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
||
55 | |||
56 | public static readonly DependencyProperty OverViewEndPointProperty = DependencyProperty.Register( |
||
57 | "OverViewEndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
||
58 | |||
59 | |||
60 | public static readonly DependencyProperty TextProperty = DependencyProperty.Register( |
||
61 | "Text", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
||
62 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
63 | "UserID", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
||
64 | public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register( |
||
65 | "FontColor", typeof(SolidColorBrush), typeof(DateControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
||
66 | //[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] |
||
67 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
68 | "StartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
69 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
70 | "EndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
||
71 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
72 | "LineSize", typeof(double), typeof(DateControl), new PropertyMetadata((double)3)); |
||
73 | public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
||
74 | "TopRightPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged)); |
||
75 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
76 | "PointSet", typeof(List<Point>), typeof(DateControl), new PropertyMetadata(new List<Point>())); |
||
77 | public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
||
78 | "LeftBottomPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged)); |
||
79 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
80 | "PathData", typeof(Geometry), typeof(DateControl), null); |
||
81 | public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DateControl), |
||
82 | new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
||
83 | |||
84 | public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(DateControl), |
||
85 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
86 | |||
87 | public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(DateControl), |
||
88 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
89 | |||
90 | #endregion |
||
91 | #region PropertyChanged Method |
||
92 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
93 | { |
||
94 | //var instance = (DateControl)sender; |
||
95 | |||
96 | //if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
97 | //{ |
||
98 | |||
99 | // instance.SetValue(e.Property, e.NewValue); |
||
100 | |||
101 | // if (instance.IsSelected) |
||
102 | // { |
||
103 | // //instance.Base_ViewBox.Style. = new SolidColorBrush(Colors.Blue); |
||
104 | // } |
||
105 | // else |
||
106 | // { |
||
107 | // //instance.Base_ViewBox.Stroke = new SolidColorBrush(Colors.Red); |
||
108 | // } |
||
109 | //} |
||
110 | } |
||
111 | |||
112 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
113 | { |
||
114 | var instance = (DateControl)sender; |
||
115 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
116 | { |
||
117 | instance.SetValue(e.Property, e.NewValue); |
||
118 | instance.SetDate(); |
||
119 | } |
||
120 | } |
||
121 | public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
122 | { |
||
123 | var instance = (DateControl)sender; |
||
124 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
125 | { |
||
126 | instance.SetValue(e.Property, e.NewValue); |
||
127 | //instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y); |
||
128 | //instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y); |
||
129 | ////instance.PointSet[0] = instance.StartPoint; |
||
130 | ////instance.PointSet[2] = instance.EndPoint; |
||
131 | instance.SetDate(); |
||
132 | } |
||
133 | } |
||
134 | public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
135 | { |
||
136 | var instance = (DateControl)sender; |
||
137 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
138 | { |
||
139 | instance.SetValue(e.Property, e.NewValue); |
||
140 | instance.SetDate(); |
||
141 | } |
||
142 | } |
||
143 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
144 | { |
||
145 | var instance = (DateControl)sender; |
||
146 | if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
147 | { |
||
148 | instance.SetValue(e.Property, e.NewValue); |
||
149 | instance.SetDate(); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
154 | { |
||
155 | var instance = (DateControl)sender; |
||
156 | if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
157 | { |
||
158 | instance.SetValue(e.Property, e.NewValue); |
||
159 | instance.SetDate(); |
||
160 | } |
||
161 | } |
||
162 | #endregion |
||
163 | #region Properties |
||
164 | public double LineSize |
||
165 | { |
||
166 | get { return (double)GetValue(LineSizeProperty); } |
||
167 | set |
||
168 | { |
||
169 | if (this.LineSize != value) |
||
170 | { |
||
171 | SetValue(LineSizeProperty, value); |
||
172 | OnPropertyChanged("LineSize"); |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | public string UserID |
||
177 | { |
||
178 | get { return (string)GetValue(UserIDProperty); } |
||
179 | set |
||
180 | { |
||
181 | if (this.UserID != value) |
||
182 | { |
||
183 | SetValue(UserIDProperty, value); |
||
184 | OnPropertyChanged("UserID"); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | public double Angle |
||
189 | { |
||
190 | get { return (double)GetValue(AngleProperty); } |
||
191 | set |
||
192 | { |
||
193 | if (this.Angle != value) |
||
194 | { |
||
195 | SetValue(AngleProperty, value); |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | |||
200 | |||
201 | |||
202 | public bool IsSelected |
||
203 | { |
||
204 | get |
||
205 | { |
||
206 | return (bool)GetValue(IsSelectedProperty); |
||
207 | } |
||
208 | set |
||
209 | { |
||
210 | SetValue(IsSelectedProperty, value); |
||
211 | OnPropertyChanged("IsSelected"); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | public ControlType ControlType |
||
216 | { |
||
217 | set |
||
218 | { |
||
219 | SetValue(ControlTypeProperty, value); |
||
220 | OnPropertyChanged("ControlType"); |
||
221 | } |
||
222 | get |
||
223 | { |
||
224 | return (ControlType)GetValue(ControlTypeProperty); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | public Geometry OverViewPathData |
||
229 | { |
||
230 | get { return (Geometry)GetValue(OverViewPathDataProperty); } |
||
231 | set |
||
232 | { |
||
233 | SetValue(OverViewPathDataProperty, value); |
||
234 | OnPropertyChanged("OverViewPathData"); |
||
235 | } |
||
236 | } |
||
237 | |||
238 | public List<Point> PointSet |
||
239 | { |
||
240 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
241 | set { SetValue(PointSetProperty, value); } |
||
242 | } |
||
243 | public Point TopRightPoint |
||
244 | { |
||
245 | get { return (Point)GetValue(TopRightPointProperty); } |
||
246 | set |
||
247 | { |
||
248 | SetValue(TopRightPointProperty, value); |
||
249 | OnPropertyChanged("TopRightPoint"); |
||
250 | } |
||
251 | } |
||
252 | public Point LeftBottomPoint |
||
253 | { |
||
254 | get { return (Point)GetValue(LeftBottomPointProperty); } |
||
255 | set |
||
256 | { |
||
257 | SetValue(LeftBottomPointProperty, value); |
||
258 | OnPropertyChanged("LeftBottomPoint"); |
||
259 | } |
||
260 | } |
||
261 | public double CenterX |
||
262 | { |
||
263 | get { return (double)GetValue(CenterXProperty); } |
||
264 | set { SetValue(CenterXProperty, value); } |
||
265 | } |
||
266 | public double CenterY |
||
267 | { |
||
268 | get { return (double)GetValue(CenterYProperty); } |
||
269 | set { SetValue(CenterYProperty, value); } |
||
270 | } |
||
271 | public string Text |
||
272 | { |
||
273 | get { return (string)GetValue(TextProperty); } |
||
274 | set |
||
275 | { |
||
276 | if (this.Text != value) |
||
277 | { |
||
278 | SetValue(TextProperty, value); |
||
279 | OnPropertyChanged("Text"); |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | public Geometry PathData |
||
284 | { |
||
285 | get { return (Geometry)GetValue(PathDataProperty); } |
||
286 | set |
||
287 | { |
||
288 | SetValue(PathDataProperty, value); |
||
289 | OnPropertyChanged("PathData"); |
||
290 | } |
||
291 | } |
||
292 | public SolidColorBrush FontColor |
||
293 | { |
||
294 | get { return (SolidColorBrush)GetValue(FontColorProperty); } |
||
295 | set |
||
296 | { |
||
297 | if (this.FontColor != value) |
||
298 | { |
||
299 | SetValue(FontColorProperty, value); |
||
300 | OnPropertyChanged("FontColor"); |
||
301 | } |
||
302 | |||
303 | } |
||
304 | } |
||
305 | public Point EndPoint |
||
306 | { |
||
307 | get { return (Point)GetValue(EndPointProperty); } |
||
308 | set |
||
309 | { |
||
310 | if (this.EndPoint != value) |
||
311 | { |
||
312 | SetValue(EndPointProperty, value); |
||
313 | OnPropertyChanged("EndPoint"); |
||
314 | } |
||
315 | } |
||
316 | } |
||
317 | public Point StartPoint |
||
318 | { |
||
319 | get { return (Point)GetValue(StartPointProperty); } |
||
320 | set |
||
321 | { |
||
322 | if (this.StartPoint != value) |
||
323 | { |
||
324 | SetValue(StartPointProperty, value); |
||
325 | OnPropertyChanged("StartPoint"); |
||
326 | } |
||
327 | } |
||
328 | } |
||
329 | |||
330 | public Point OverViewStartPoint |
||
331 | { |
||
332 | get { return (Point)GetValue(OverViewStartPointProperty); } |
||
333 | set { SetValue(OverViewStartPointProperty, value); } |
||
334 | } |
||
335 | |||
336 | public Point OverViewEndPoint |
||
337 | { |
||
338 | get { return (Point)GetValue(OverViewEndPointProperty); } |
||
339 | set { SetValue(OverViewEndPointProperty, value); } |
||
340 | } |
||
341 | |||
342 | //public int MyProperty { get; set; } |
||
343 | |||
344 | |||
345 | #endregion |
||
346 | #region Data |
||
347 | LineGeometry p1 = new LineGeometry(); |
||
348 | LineGeometry p2 = new LineGeometry(); |
||
349 | LineGeometry p3 = new LineGeometry(); |
||
350 | LineGeometry p4 = new LineGeometry(); |
||
351 | GeometryGroup instanceGroup = new GeometryGroup(); |
||
352 | FormattedText text; |
||
353 | #endregion |
||
354 | public override void OnApplyTemplate() |
||
355 | { |
||
356 | base.OnApplyTemplate(); |
||
357 | Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox; |
||
358 | Base_TextBox = GetTemplateChild(PART_TextBox) as TextBlock; |
||
359 | Base_TextBox.Visibility = System.Windows.Visibility.Hidden; |
||
360 | SetDate(); |
||
361 | } |
||
362 | public void SetDate() |
||
363 | { |
||
364 | if (Text == null) |
||
365 | { |
||
366 | Text = DateTime.Now.ToString("yyyy-MM-dd"); |
||
367 | } |
||
368 | this.ApplyTemplate(); |
||
369 | instanceGroup.Children.Clear(); |
||
370 | Base_TextBox.Visibility = System.Windows.Visibility.Visible; |
||
371 | Point mid = MathSet.FindCentroid(new List<Point>() |
||
372 | { |
||
373 | this.StartPoint, |
||
374 | this.LeftBottomPoint, |
||
375 | this.EndPoint, |
||
376 | this.TopRightPoint, |
||
377 | }); |
||
378 | |||
379 | |||
380 | double AngleData = this.Angle * -1; |
||
381 | |||
382 | PathFigure pathFigure = new PathFigure(); |
||
383 | pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
384 | |||
385 | LineSegment lineSegment0 = new LineSegment(); |
||
386 | lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
387 | pathFigure.Segments.Add(lineSegment0); |
||
388 | |||
389 | LineSegment lineSegment1 = new LineSegment(); |
||
390 | lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
||
391 | pathFigure.Segments.Add(lineSegment1); |
||
392 | |||
393 | LineSegment lineSegment2 = new LineSegment(); |
||
394 | lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
||
395 | pathFigure.Segments.Add(lineSegment2); |
||
396 | |||
397 | LineSegment lineSegment3 = new LineSegment(); |
||
398 | lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
||
399 | pathFigure.Segments.Add(lineSegment3); |
||
400 | |||
401 | PathGeometry pathGeometry = new PathGeometry(); |
||
402 | pathGeometry.Figures = new PathFigureCollection(); |
||
403 | pathFigure.IsClosed = true; |
||
404 | pathGeometry.Figures.Add(pathFigure); |
||
405 | this.Base_ViewBox.Width = pathGeometry.Bounds.Width; |
||
406 | this.Base_ViewBox.Height = pathGeometry.Bounds.Height; |
||
407 | this.Tag = pathGeometry; |
||
408 | |||
409 | Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2); |
||
410 | Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2); |
||
411 | |||
412 | //CenterX = MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2; |
||
413 | //CenterY = MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2; |
||
414 | |||
415 | instanceGroup.Children.Add(pathGeometry); |
||
416 | |||
417 | text = new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, |
||
418 | FlowDirection.LeftToRight, new Typeface("Tahoma"), 16, Brushes.Black); |
||
419 | |||
420 | instanceGroup.Children.Add(text.BuildGeometry(new Point(10,10))); |
||
421 | |||
422 | PathData = instanceGroup; |
||
423 | //OverViewPathData = PathData; |
||
424 | |||
425 | |||
426 | } |
||
427 | |||
428 | public event PropertyChangedEventHandler PropertyChanged; |
||
429 | protected void OnPropertyChanged(string propName) |
||
430 | { |
||
431 | if (PropertyChanged != null) |
||
432 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
||
433 | } |
||
434 | |||
435 | public void Dispose() |
||
436 | { |
||
437 | GC.Collect(); |
||
438 | GC.SuppressFinalize(this); |
||
439 | } |
||
440 | |||
441 | public void ApplyOverViewData() |
||
442 | { |
||
443 | //this.OverViewPathData = this.PathData; |
||
444 | this.OverViewStartPoint = this.StartPoint; |
||
445 | this.OverViewEndPoint = this.EndPoint; |
||
446 | } |
||
447 | |||
448 | public void updateControl() |
||
449 | { |
||
450 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
451 | this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
||
452 | this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
453 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
454 | this.SetDate(); |
||
455 | } |
||
456 | } |
||
457 | } |