1
|
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
|
|
16
|
namespace MarkupToPDF.Controls.Shape
|
17
|
{
|
18
|
//[TemplatePart(Name = "PART_TriPath", Type = typeof(Path))]
|
19
|
public class TriControl : Control, IDisposable, INotifyPropertyChanged, IPath, IMarkupCommonData, IShapeControl, IDashControl
|
20
|
{
|
21
|
public Path Base_TriPath { get; set; }
|
22
|
//public enum PaintSet { None, Fill, Hatch };
|
23
|
private const string PART_TriPath = "PART_TriPath";
|
24
|
|
25
|
//public Path Base_TriPath = null;
|
26
|
|
27
|
static TriControl()
|
28
|
{
|
29
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(TriControl), new FrameworkPropertyMetadata(typeof(TriControl)));
|
30
|
ResourceDictionary dictionary = new ResourceDictionary();
|
31
|
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
|
32
|
Application.Current.Resources.MergedDictionaries.Add(dictionary);
|
33
|
}
|
34
|
|
35
|
#region Dependency Properties
|
36
|
|
37
|
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
|
38
|
"OverViewPathData", typeof(Geometry), typeof(TriControl), new PropertyMetadata(null));
|
39
|
|
40
|
public static readonly DependencyProperty IsSelectedProperty =
|
41
|
DependencyProperty.Register("IsSelected", typeof(bool), typeof(TriControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
|
42
|
|
43
|
public static readonly DependencyProperty ControlTypeProperty =
|
44
|
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TriControl), new FrameworkPropertyMetadata(ControlType.Triangle));
|
45
|
|
46
|
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
|
47
|
"LineSize", typeof(double), typeof(TriControl), new PropertyMetadata((Double)1));
|
48
|
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
|
49
|
"UserID", typeof(string), typeof(TriControl), new PropertyMetadata(null));
|
50
|
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
|
51
|
"DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }));
|
52
|
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
|
53
|
"PathData", typeof(Geometry), typeof(TriControl), null);
|
54
|
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
|
55
|
"StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
|
56
|
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
|
57
|
"FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
|
58
|
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
|
59
|
"EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
60
|
public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
|
61
|
"MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
62
|
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
|
63
|
"StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
64
|
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
|
65
|
"Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None));
|
66
|
|
67
|
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
|
68
|
"PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
|
69
|
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new
|
70
|
PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
|
71
|
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl),
|
72
|
new PropertyMetadata((double)0, OnCenterXYChanged));
|
73
|
|
74
|
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl),
|
75
|
new PropertyMetadata((double)0, OnCenterXYChanged));
|
76
|
|
77
|
#endregion
|
78
|
#region PropertyChanged Method
|
79
|
|
80
|
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
81
|
{
|
82
|
var instance = (TriControl)sender;
|
83
|
|
84
|
if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
|
85
|
{
|
86
|
|
87
|
instance.SetValue(e.Property, e.NewValue);
|
88
|
|
89
|
if (instance.IsSelected)
|
90
|
{
|
91
|
instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
|
92
|
}
|
93
|
else
|
94
|
{
|
95
|
instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
|
100
|
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
101
|
{
|
102
|
var instance = (TriControl)sender;
|
103
|
|
104
|
if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
|
105
|
{
|
106
|
instance.SetValue(e.Property, e.NewValue);
|
107
|
instance.SetTri();
|
108
|
}
|
109
|
}
|
110
|
|
111
|
|
112
|
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
113
|
{
|
114
|
var instance = (TriControl)sender;
|
115
|
if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
|
116
|
{
|
117
|
instance.SetValue(e.Property, e.NewValue);
|
118
|
instance.SetTri();
|
119
|
}
|
120
|
}
|
121
|
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
122
|
{
|
123
|
var instance = (TriControl)sender;
|
124
|
if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
|
125
|
{
|
126
|
instance.SetValue(e.Property, e.NewValue);
|
127
|
instance.SetTri();
|
128
|
}
|
129
|
}
|
130
|
#endregion
|
131
|
#region Properties
|
132
|
|
133
|
public Double LineSize
|
134
|
{
|
135
|
get { return (Double)GetValue(LineSizeProperty); }
|
136
|
set
|
137
|
{
|
138
|
if (this.LineSize != value)
|
139
|
{
|
140
|
SetValue(LineSizeProperty, value);
|
141
|
}
|
142
|
}
|
143
|
}
|
144
|
public string UserID
|
145
|
{
|
146
|
get { return (string)GetValue(UserIDProperty); }
|
147
|
set
|
148
|
{
|
149
|
if (this.UserID != value)
|
150
|
{
|
151
|
SetValue(UserIDProperty, value);
|
152
|
OnPropertyChanged("UserID");
|
153
|
}
|
154
|
}
|
155
|
}
|
156
|
public SolidColorBrush FillColor
|
157
|
{
|
158
|
get { return (SolidColorBrush)GetValue(FillColorProperty); }
|
159
|
set
|
160
|
{
|
161
|
if (this.FillColor != value)
|
162
|
{
|
163
|
SetValue(FillColorProperty, value);
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
public DoubleCollection DashSize
|
168
|
{
|
169
|
get { return (DoubleCollection)GetValue(DashSizeProperty); }
|
170
|
set
|
171
|
{
|
172
|
if (this.DashSize != value)
|
173
|
{
|
174
|
SetValue(DashSizeProperty, value);
|
175
|
}
|
176
|
}
|
177
|
}
|
178
|
public PaintSet Paint
|
179
|
{
|
180
|
get { return (PaintSet)GetValue(PaintProperty); }
|
181
|
set
|
182
|
{
|
183
|
if (this.Paint != value)
|
184
|
{
|
185
|
SetValue(PaintProperty, value);
|
186
|
}
|
187
|
}
|
188
|
}
|
189
|
|
190
|
|
191
|
public SolidColorBrush StrokeColor
|
192
|
{
|
193
|
get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
|
194
|
set
|
195
|
{
|
196
|
if (this.StrokeColor != value)
|
197
|
{
|
198
|
SetValue(StrokeColorProperty, value);
|
199
|
}
|
200
|
}
|
201
|
}
|
202
|
public Geometry OverViewPathData
|
203
|
{
|
204
|
get
|
205
|
{
|
206
|
return (Geometry)GetValue(OverViewPathDataProperty);
|
207
|
}
|
208
|
set
|
209
|
{
|
210
|
SetValue(OverViewPathDataProperty, value);
|
211
|
OnPropertyChanged("OverViewPathData");
|
212
|
}
|
213
|
}
|
214
|
public Geometry PathData
|
215
|
{
|
216
|
get { return (Geometry)GetValue(PathDataProperty); }
|
217
|
set { SetValue(PathDataProperty, value); }
|
218
|
}
|
219
|
public Point EndPoint
|
220
|
{
|
221
|
get { return (Point)GetValue(EndPointProperty); }
|
222
|
set { SetValue(EndPointProperty, value); }
|
223
|
}
|
224
|
public Point StartPoint
|
225
|
{
|
226
|
get { return (Point)GetValue(StartPointProperty); }
|
227
|
set { SetValue(StartPointProperty, value); }
|
228
|
}
|
229
|
public Point MidPoint
|
230
|
{
|
231
|
get { return (Point)GetValue(MidPointProperty); }
|
232
|
set { SetValue(MidPointProperty, value); }
|
233
|
}
|
234
|
public List<Point> PointSet
|
235
|
{
|
236
|
get { return (List<Point>)GetValue(PointSetProperty); }
|
237
|
set { SetValue(PointSetProperty, value); }
|
238
|
}
|
239
|
|
240
|
public bool IsSelected
|
241
|
{
|
242
|
get
|
243
|
{
|
244
|
return (bool)GetValue(IsSelectedProperty);
|
245
|
}
|
246
|
set
|
247
|
{
|
248
|
SetValue(IsSelectedProperty, value);
|
249
|
}
|
250
|
}
|
251
|
|
252
|
public ControlType ControlType
|
253
|
{
|
254
|
get
|
255
|
{
|
256
|
return (ControlType)GetValue(ControlTypeProperty);
|
257
|
}
|
258
|
set
|
259
|
{
|
260
|
SetValue(ControlTypeProperty, value);
|
261
|
}
|
262
|
}
|
263
|
|
264
|
|
265
|
public double Angle
|
266
|
{
|
267
|
get { return (double)GetValue(AngleProperty); }
|
268
|
set
|
269
|
{
|
270
|
if (this.Angle != value)
|
271
|
{
|
272
|
SetValue(AngleProperty, value);
|
273
|
}
|
274
|
}
|
275
|
}
|
276
|
public double CenterX
|
277
|
{
|
278
|
get { return (double)GetValue(CenterXProperty); }
|
279
|
set { SetValue(CenterXProperty, value); }
|
280
|
}
|
281
|
public double CenterY
|
282
|
{
|
283
|
get { return (double)GetValue(CenterYProperty); }
|
284
|
set { SetValue(CenterYProperty, value); }
|
285
|
}
|
286
|
#endregion
|
287
|
|
288
|
#region Dependency PropertyChanged
|
289
|
//public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
290
|
//{
|
291
|
// var instance = (TriControl)sender;
|
292
|
|
293
|
// if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
|
294
|
// {
|
295
|
|
296
|
// instance.SetValue(e.Property, e.NewValue);
|
297
|
|
298
|
// if (instance.IsSelected)
|
299
|
// {
|
300
|
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
|
301
|
// }
|
302
|
// else
|
303
|
// {
|
304
|
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
|
305
|
// }
|
306
|
// }
|
307
|
//}
|
308
|
|
309
|
#endregion Dependency PropertyChanged
|
310
|
|
311
|
public override void OnApplyTemplate()
|
312
|
{
|
313
|
base.OnApplyTemplate();
|
314
|
Base_TriPath = GetTemplateChild(PART_TriPath) as Path;
|
315
|
|
316
|
if (Base_TriPath == null)
|
317
|
{
|
318
|
return;
|
319
|
}
|
320
|
}
|
321
|
public void SetTri()
|
322
|
{
|
323
|
this.ApplyTemplate();
|
324
|
Base_TriPath.StrokeDashArray.Clear();
|
325
|
foreach (var item in this.DashSize)
|
326
|
{
|
327
|
Base_TriPath.StrokeDashArray.Add(item);
|
328
|
}
|
329
|
Base_TriPath.StrokeDashCap = PenLineCap.Square;
|
330
|
PathFigure pathFigure = new PathFigure();
|
331
|
|
332
|
//this.FillColor = this.StrokeColor;
|
333
|
////Base_TriPath.Fill = this.FillColor;
|
334
|
//Base_TriPath.Fill = Brushes.Red;
|
335
|
//pathFigure.IsFilled = true;
|
336
|
|
337
|
switch (this.Paint)
|
338
|
{
|
339
|
case PaintSet.None:
|
340
|
this.FillColor = null;
|
341
|
pathFigure.IsFilled = false;
|
342
|
break;
|
343
|
case PaintSet.Rect:
|
344
|
this.FillColor = this.StrokeColor;
|
345
|
Base_TriPath.Fill = this.FillColor;
|
346
|
pathFigure.IsFilled = true;
|
347
|
break;
|
348
|
case PaintSet.Cloud:
|
349
|
Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
|
350
|
pathFigure.IsFilled = true;
|
351
|
break;
|
352
|
default:
|
353
|
break;
|
354
|
}
|
355
|
pathFigure.StartPoint = this.StartPoint;
|
356
|
|
357
|
LineSegment lineSegment0 = new LineSegment();
|
358
|
lineSegment0.Point = this.StartPoint;
|
359
|
pathFigure.Segments.Add(lineSegment0);
|
360
|
|
361
|
LineSegment lineSegment1 = new LineSegment();
|
362
|
|
363
|
if (MidPoint.X != 0 && MidPoint.Y != 0)
|
364
|
{
|
365
|
lineSegment1.Point = this.MidPoint;
|
366
|
pathFigure.Segments.Add(lineSegment1);
|
367
|
}
|
368
|
else
|
369
|
{
|
370
|
lineSegment1.Point = this.EndPoint;
|
371
|
pathFigure.Segments.Add(lineSegment1);
|
372
|
}
|
373
|
|
374
|
LineSegment lineSegment2 = new LineSegment();
|
375
|
lineSegment2.Point = this.EndPoint;
|
376
|
pathFigure.Segments.Add(lineSegment2);
|
377
|
|
378
|
|
379
|
PathGeometry pathGeometry = new PathGeometry();
|
380
|
pathGeometry.Figures = new PathFigureCollection();
|
381
|
pathFigure.IsClosed = true;
|
382
|
pathGeometry.Figures.Add(pathFigure);
|
383
|
//this.FillColor = new SolidColorBrush(Colors.Red);
|
384
|
FillColor = Brushes.Red;
|
385
|
this.PathData = pathGeometry;
|
386
|
ApplyOverViewData();
|
387
|
|
388
|
}
|
389
|
public void Dispose()
|
390
|
{
|
391
|
GC.Collect();
|
392
|
GC.SuppressFinalize(this);
|
393
|
}
|
394
|
public event PropertyChangedEventHandler PropertyChanged;
|
395
|
protected void OnPropertyChanged(string propName)
|
396
|
{
|
397
|
if (PropertyChanged != null)
|
398
|
PropertyChanged(this, new PropertyChangedEventArgs(propName));
|
399
|
}
|
400
|
|
401
|
public void ApplyOverViewData()
|
402
|
{
|
403
|
this.OverViewPathData = this.PathData;
|
404
|
}
|
405
|
|
406
|
public void updateControl()
|
407
|
{
|
408
|
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
|
409
|
this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
|
410
|
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
|
411
|
}
|
412
|
|
413
|
//public void ChangePaint(PaintSet state)
|
414
|
//{
|
415
|
// this.Paint = state;
|
416
|
// this.SetTri();
|
417
|
//}
|
418
|
}
|
419
|
}
|