MoveThumb.cs
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace RoboforkApp
{
public class MoveThumb : Thumb
{
private DesignerItem designerItem;
private DesignerCanvas designerCanvas;
public MoveThumb()
{
DragStarted += new DragStartedEventHandler(this.MoveThumb_DragStarted);
DragDelta += new DragDeltaEventHandler(this.MoveThumb_DragDelta);
}
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e)
{
this.designerItem = DataContext as DesignerItem;
if (this.designerItem != null)
{
this.designerCanvas = VisualTreeHelper.GetParent(this.designerItem) as DesignerCanvas;
}
}
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
if (this.designerItem != null && this.designerCanvas != null && this.designerItem.IsSelected)
{
double minLeft = double.MaxValue;
double minTop = double.MaxValue;
foreach (DesignerItem item in this.designerCanvas.SelectedItems)
{
minLeft = Math.Min(Canvas.GetLeft(item), minLeft);
minTop = Math.Min(Canvas.GetTop(item), minTop);
}
double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
double deltaVertical = Math.Max(-minTop, e.VerticalChange);
foreach (DesignerItem item in this.designerCanvas.SelectedItems)
{
Canvas.SetLeft(item, Canvas.GetLeft(item) + deltaHorizontal);
Canvas.SetTop(item, Canvas.GetTop(item) + deltaVertical);
}
this.designerCanvas.InvalidateMeasure();
e.Handled = true;
}
}
}
}