markus / MarkupToPDF / Controls / Angle / AngleControl.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (3.92 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Windows; |
6 |
using System.Windows.Controls; |
7 |
|
8 |
namespace MarkupToPDF.Controls.Angle |
9 |
{ |
10 |
[TemplatePart(Name = "PART_AngleText", Type = typeof(TextBlock))] |
11 |
public class AngleControl : Control |
12 |
{ |
13 |
private const string PART_AngleText = "PART_AngleText"; |
14 |
public TextBlock Base_AngleText = null; |
15 |
|
16 |
public AngleControl()//Point p1, Point p2) |
17 |
{ |
18 |
//this.DefaultStyleKey = typeof(AngleControl); |
19 |
} |
20 |
// AngleValue = MathSet.AngleMethod(p1.X, p1.Y, p2.X, p2.Y).ToString("###.#") + "°"; |
21 |
//instanceMargin = new Thickness(p2.X + 30, p2.Y, 0, 0); |
22 |
|
23 |
#region Dependency Properties |
24 |
|
25 |
public static readonly DependencyProperty AngleValueProperty = DependencyProperty.Register( |
26 |
"AngleValue", typeof(string), typeof(AngleControl), new PropertyMetadata(null)); |
27 |
|
28 |
public static readonly DependencyProperty MarginValueProperty = DependencyProperty.Register( |
29 |
"instanceMargin", typeof(Thickness), typeof(AngleControl), new PropertyMetadata(null)); |
30 |
|
31 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
32 |
"StartPoint", typeof(Point), typeof(AngleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
33 |
|
34 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
35 |
"EndPoint", typeof(Point), typeof(AngleControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
36 |
#endregion |
37 |
#region PropertyChanged Method |
38 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
39 |
{ |
40 |
var instance = (AngleControl)sender; |
41 |
if (e.OldValue != e.NewValue && instance.Base_AngleText != null) |
42 |
{ |
43 |
instance.SetValue(e.Property, e.NewValue); |
44 |
instance.SetAngleText(); |
45 |
} |
46 |
} |
47 |
#endregion |
48 |
#region Properties |
49 |
public string AngleValue |
50 |
{ |
51 |
get { return (string)GetValue(AngleValueProperty); } |
52 |
set { SetValue(AngleValueProperty, value); } |
53 |
} |
54 |
|
55 |
public Thickness instanceMargin |
56 |
{ |
57 |
get { return (Thickness)GetValue(MarginValueProperty); } |
58 |
set { SetValue(MarginValueProperty, value); } |
59 |
} |
60 |
public Point EndPoint |
61 |
{ |
62 |
get { return (Point)GetValue(EndPointProperty); } |
63 |
set { SetValue(EndPointProperty, value); } |
64 |
} |
65 |
public Point StartPoint |
66 |
{ |
67 |
get { return (Point)GetValue(StartPointProperty); } |
68 |
set { SetValue(StartPointProperty, value); } |
69 |
} |
70 |
#endregion |
71 |
#region Object & Variable |
72 |
#endregion |
73 |
|
74 |
public override void OnApplyTemplate() |
75 |
{ |
76 |
base.OnApplyTemplate(); |
77 |
Base_AngleText = GetTemplateChild(PART_AngleText) as TextBlock; |
78 |
} |
79 |
private void SetAngleText() |
80 |
{ |
81 |
var x = Math.Abs((Math.Abs(this.StartPoint.X) - Math.Abs(this.EndPoint.X))); |
82 |
var y = Math.Abs((Math.Abs(this.StartPoint.Y) - Math.Abs(this.EndPoint.Y))); |
83 |
if (x > y) |
84 |
{ |
85 |
this.instanceMargin = new Thickness(this.EndPoint.X + 30, this.EndPoint.Y, 0, 0); |
86 |
} |
87 |
else |
88 |
{ |
89 |
this.instanceMargin = new Thickness(this.EndPoint.X - 30, this.EndPoint.Y, 0, 0); |
90 |
} |
91 |
|
92 |
//if (this.StartPoint == new Point(0, 0) && this.EndPoint == new Point(0, 0)) |
93 |
//{ |
94 |
|
95 |
//} |
96 |
//else |
97 |
//{ |
98 |
// this.AngleValue = MathSet.AngleMethod(this.StartPoint.X, this.StartPoint.Y, this.EndPoint.X, this.EndPoint.Y).ToString("###.#") + "°"; |
99 |
//} |
100 |
this.Width = this.Base_AngleText.Width; |
101 |
this.Height = this.Base_AngleText.Height; |
102 |
} |
103 |
} |
104 |
} |