Mercurial > silverbladetech
comparison Chronosv2/source/DragAndDrop/DragAdorner.cs @ 10:443821e55f06
Initial cleaned up add from Codeplex files
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Tue, 21 Feb 2012 17:25:44 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:904a9faadf8b | 10:443821e55f06 |
---|---|
1 using System.Windows; | |
2 using System.Windows.Documents; | |
3 using System.Windows.Media; | |
4 using System.Windows.Shapes; | |
5 | |
6 namespace Chronos.Presentation.DragAndDrop | |
7 { | |
8 public sealed class DragAdorner : Adorner | |
9 { | |
10 #region · Fields · | |
11 | |
12 private UIElement child; | |
13 private UIElement owner; | |
14 private double XCenter; | |
15 private double YCenter; | |
16 private double topOffset; | |
17 private double leftOffset; | |
18 | |
19 #endregion | |
20 | |
21 #region · Properties · | |
22 | |
23 public double LeftOffset | |
24 { | |
25 get { return this.leftOffset; } | |
26 set | |
27 { | |
28 this.leftOffset = (value - this.XCenter); | |
29 this.UpdatePosition(); | |
30 } | |
31 } | |
32 | |
33 public double TopOffset | |
34 { | |
35 get { return this.topOffset; } | |
36 set | |
37 { | |
38 this.topOffset = (value - this.YCenter); | |
39 this.UpdatePosition(); | |
40 } | |
41 } | |
42 | |
43 #endregion | |
44 | |
45 #region · Protected Properties · | |
46 | |
47 protected override int VisualChildrenCount | |
48 { | |
49 get { return 1; } | |
50 } | |
51 | |
52 #endregion | |
53 | |
54 #region · Constructors · | |
55 | |
56 public DragAdorner(UIElement owner) | |
57 : base(owner) | |
58 { | |
59 } | |
60 | |
61 public DragAdorner(UIElement owner, UIElement adornElement, bool useVisualBrush, double opacity) | |
62 : base(owner) | |
63 { | |
64 this.owner = owner; | |
65 | |
66 if (useVisualBrush) | |
67 { | |
68 VisualBrush brush = new VisualBrush(adornElement); | |
69 Rectangle rect = new Rectangle(); | |
70 | |
71 brush.Opacity = opacity; | |
72 rect.RadiusX = 3; | |
73 rect.RadiusY = 3; | |
74 rect.Width = adornElement.DesiredSize.Width; | |
75 rect.Height = adornElement.DesiredSize.Height; | |
76 | |
77 this.XCenter = adornElement.DesiredSize.Width / 2; | |
78 this.YCenter = adornElement.DesiredSize.Height / 2; | |
79 | |
80 rect.Fill = brush; | |
81 | |
82 this.child = rect; | |
83 } | |
84 else | |
85 { | |
86 this.child = adornElement; | |
87 } | |
88 } | |
89 | |
90 #endregion | |
91 | |
92 #region · Methods · | |
93 | |
94 public override GeneralTransform GetDesiredTransform(GeneralTransform transform) | |
95 { | |
96 GeneralTransformGroup result = new GeneralTransformGroup(); | |
97 | |
98 result.Children.Add(base.GetDesiredTransform(transform)); | |
99 result.Children.Add(new TranslateTransform(this.leftOffset, this.topOffset)); | |
100 | |
101 return result; | |
102 } | |
103 | |
104 #endregion | |
105 | |
106 #region · Protected Methods · | |
107 | |
108 protected override Visual GetVisualChild(int index) | |
109 { | |
110 return this.child; | |
111 } | |
112 | |
113 protected override Size MeasureOverride(Size finalSize) | |
114 { | |
115 this.child.Measure(finalSize); | |
116 | |
117 return this.child.DesiredSize; | |
118 } | |
119 | |
120 protected override Size ArrangeOverride(Size finalSize) | |
121 { | |
122 this.child.Arrange(new Rect(this.child.DesiredSize)); | |
123 | |
124 return finalSize; | |
125 } | |
126 | |
127 #endregion | |
128 | |
129 #region · Private Methods · | |
130 | |
131 private void UpdatePosition() | |
132 { | |
133 AdornerLayer adorner = (AdornerLayer)this.Parent; | |
134 | |
135 if (adorner != null) | |
136 { | |
137 adorner.Update(this.AdornedElement); | |
138 } | |
139 } | |
140 | |
141 #endregion | |
142 } | |
143 } |