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