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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Tango.SharedUI.Helpers;
namespace Tango.DragAndDrop
{
/// <summary>
/// <para><img class="classImage" src="../Media/DragAndDropService.png" /></para>
/// Represents a drag and drop service which exposes several attached properties and events to create an interactive drag and drop functionality.
/// </summary>
/// <example>
/// <para class="example-title">
/// <img class="exampleIcon" src="../Icons/CodeExample.png" />
/// <i>
/// The following example demonstrates how to use the Drag and Drop service and the <see cref="DraggingSurface"/> to easily create drag and drop features.
/// </i>
/// </para>
/// <para>
/// <markup><video class="exampleVideo" autoplay="autoplay" controls="controls" loop="loop" src="../Media/DragAndDropExample.mp4"></video></markup>
/// </para>
/// <code lang="XAML" source="../FullAPIExamples/Examples/DragAndDrop/DragAndDropExample.xaml" title="Drag and Drop Example." />
/// </example>
/// <seealso cref="DraggingSurface" />
/// <seealso cref="DropEventArgs" />
public static class DragAndDropService
{
private static List<FrameworkElement> _dragElements;
private static List<FrameworkElement> _dropElements;
private static Point _mouseDownLocation;
private static FrameworkElement _currentDragedElement;
private static FrameworkElement _currentDropElement;
private static bool _isMouseDown;
private static DispatcherTimer _dragTimer;
private static Border _dragBorder;
private const int MIN_DRAG_OFFSET = 8;
#region Events
public static event EventHandler<FrameworkElement> DragStarted;
public static event EventHandler<FrameworkElement> DragEnded;
#endregion
#region Delegates
/// <summary>
/// Represents the attached <see cref="DropEvent"/> event delegate.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="DropEventArgs"/> instance containing the event data.</param>
public delegate void DropEventHandler(object sender, DropEventArgs e);
#endregion
#region Constructors
/// <summary>
/// Initializes the <see cref="DragAndDropService"/> class.
/// </summary>
static DragAndDropService()
{
_dragElements = new List<FrameworkElement>();
_dropElements = new List<FrameworkElement>();
_dragTimer = new DispatcherTimer();
_dragTimer.Interval = TimeSpan.FromMilliseconds(30);
_dragTimer.Tick += DragTimer_Tick;
_dragTimer.IsEnabled = false;
}
#endregion
#region Attached Properties
#region Draggable
/// <summary>
/// Determines whether an element is draggable by the drag and drop service.
/// </summary>
public static readonly DependencyProperty DraggableProperty =
DependencyProperty.RegisterAttached("Draggable",
typeof(bool), typeof(DragAndDropService),
new FrameworkPropertyMetadata(false, DraggableChanged));
/// <summary>
/// Draggable changed.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void DraggableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
RegisterDraggable(d as FrameworkElement);
}
else
{
UnRegisterDraggable(d as FrameworkElement);
}
}
/// <summary>
/// Sets the draggable attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public static void SetDraggable(FrameworkElement element, bool value)
{
element.SetValue(DraggableProperty, value);
}
/// <summary>
/// Gets the draggable attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static bool GetDraggable(FrameworkElement element)
{
return (bool)element.GetValue(DraggableProperty);
}
#endregion
#region IsDragging
/// <summary>
/// Determines whether the draggable element is currently being dragged.
/// </summary>
public static readonly DependencyProperty IsDraggingProperty =
DependencyProperty.RegisterAttached("IsDragging",
typeof(bool), typeof(DragAndDropService),
new FrameworkPropertyMetadata(false));
/// <summary>
/// Sets the IsDragging attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public static void SetIsDragging(FrameworkElement element, bool value)
{
element.SetValue(IsDraggingProperty, value);
}
/// <summary>
/// Gets the is dragging attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static bool GetIsDragging(FrameworkElement element)
{
return (bool)element.GetValue(IsDraggingProperty);
}
#endregion
#region DraggableBackground
/// <summary>
/// Determines the draggable element replication background.
/// </summary>
public static readonly DependencyProperty DraggableBackgroundProperty =
DependencyProperty.RegisterAttached("DraggableBackground",
typeof(Brush), typeof(DragAndDropService),
new FrameworkPropertyMetadata(null));
/// <summary>
/// Sets the draggable background attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
public static void SetDraggableBackground(FrameworkElement element, Brush value)
{
element.SetValue(DraggableBackgroundProperty, value);
}
/// <summary>
/// Gets the draggable background attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static Brush GetDraggableBackground(FrameworkElement element)
{
return (Brush)element.GetValue(DraggableBackgroundProperty);
}
#endregion
#region DraggableBorderBrush
/// <summary>
/// Determines the draggable element replication border brush.
/// </summary>
public static readonly DependencyProperty DraggableBorderBrushProperty =
DependencyProperty.RegisterAttached("DraggableBorderBrush",
typeof(Brush), typeof(DragAndDropService),
new FrameworkPropertyMetadata(null));
/// <summary>
/// Sets the draggable border brush attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
public static void SetDraggableBorderBrush(FrameworkElement element, Brush value)
{
element.SetValue(DraggableBorderBrushProperty, value);
}
/// <summary>
/// Gets the draggable border brush attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static Brush GetDraggableBorderBrush(FrameworkElement element)
{
return (Brush)element.GetValue(DraggableBorderBrushProperty);
}
#endregion
#region DraggableOpacity
/// <summary>
/// Determines the draggable element replication opacity.
/// </summary>
public static readonly DependencyProperty DraggableOpacityProperty =
DependencyProperty.RegisterAttached("DraggableOpacity",
typeof(double), typeof(DragAndDropService),
new FrameworkPropertyMetadata(0.8));
/// <summary>
/// Sets the draggable opacity attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
public static void SetDraggableOpacity(FrameworkElement element, double value)
{
element.SetValue(DraggableOpacityProperty, value);
}
/// <summary>
/// Gets the draggable opacity attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static double GetDraggableOpacity(FrameworkElement element)
{
return (double)element.GetValue(DraggableOpacityProperty);
}
#endregion
#region Droppable
/// <summary>
/// Determines whether an element is a dropable target by the drag and drop service.
/// </summary>
public static readonly DependencyProperty DroppableProperty =
DependencyProperty.RegisterAttached("Droppable",
typeof(bool), typeof(DragAndDropService),
new FrameworkPropertyMetadata(false, DroppableChanged));
/// <summary>
/// Droppables the changed attached property.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void DroppableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
RegisterDroppable(d as FrameworkElement);
}
else
{
UnRegisterDroppable(d as FrameworkElement);
}
}
/// <summary>
/// Sets the droppable attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public static void SetDroppable(FrameworkElement element, bool value)
{
element.SetValue(DroppableProperty, value);
}
/// <summary>
/// Gets the droppable attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static bool GetDroppable(FrameworkElement element)
{
return (bool)element.GetValue(DroppableProperty);
}
#endregion
#region IsDraggableOver
/// <summary>
/// Determines whether a draggable element currently hovers over the droppable element.
/// </summary>
public static readonly DependencyProperty IsDraggableOverProperty =
DependencyProperty.RegisterAttached("IsDraggableOver",
typeof(bool), typeof(DragAndDropService),
new FrameworkPropertyMetadata(false));
/// <summary>
/// Sets the is draggable over attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">if set to <c>true</c> [value].</param>
public static void SetIsDraggableOver(FrameworkElement element, bool value)
{
element.SetValue(IsDraggableOverProperty, value);
}
/// <summary>
/// Gets the is draggable over attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static bool GetIsDraggableOver(FrameworkElement element)
{
return (bool)element.GetValue(IsDraggableOverProperty);
}
#endregion
#region Dragging Surface
/// <summary>
/// Determines the Draggable dragging surface.
/// </summary>
public static readonly DependencyProperty DraggingSurfaceProperty =
DependencyProperty.RegisterAttached("DraggingSurface",
typeof(DraggingSurface), typeof(DragAndDropService),
new FrameworkPropertyMetadata(null, DraggingSurfaceChanged));
/// <summary>
/// Dragging the surface changed.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void DraggingSurfaceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
/// <summary>
/// Sets the dragging surface attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="value">The value.</param>
public static void SetDraggingSurface(FrameworkElement element, DraggingSurface value)
{
element.SetValue(DraggingSurfaceProperty, value);
}
/// <summary>
/// Gets the dragging surface attached property.
/// </summary>
/// <param name="element">The element.</param>
/// <returns></returns>
public static DraggingSurface GetDraggingSurface(FrameworkElement element)
{
return (DraggingSurface)element.GetValue(DraggingSurfaceProperty);
}
#endregion
#endregion
#region Attached Events
/// <summary>
/// Occurs when a successful drop has occurred.
/// </summary>
public static readonly RoutedEvent DropEvent =
EventManager.RegisterRoutedEvent("Drop",
RoutingStrategy.Bubble,
typeof(DropEventHandler),
typeof(DragAndDropService));
/// <summary>
/// Adds the drop event handler.
/// </summary>
/// <param name="o">The o.</param>
/// <param name="handler">The handler.</param>
public static void AddDropHandler(DependencyObject o, DropEventHandler handler)
{
((UIElement)o).AddHandler(DropEvent, handler);
}
/// <summary>
/// Removes the drop event handler.
/// </summary>
/// <param name="o">The o.</param>
/// <param name="handler">The handler.</param>
public static void RemoveDropHandler(DependencyObject o, DropEventHandler handler)
{
((UIElement)o).RemoveHandler(DropEvent, handler);
}
#endregion
#region Drag Timer
/// <summary>
/// Handles the Tick event of the DragTimer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private static void DragTimer_Tick(object sender, EventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Pressed && _currentDragedElement != null)
{
DragStarted?.Invoke(_currentDragedElement, _currentDragedElement);
var surface = GetDraggingSurface(_currentDragedElement);
var rootElement = surface.Parent as FrameworkElement;
DraggingSurface.SetLeft(_dragBorder, Mouse.GetPosition(surface).X - _mouseDownLocation.X);
DraggingSurface.SetTop(_dragBorder, Mouse.GetPosition(surface).Y - _mouseDownLocation.Y);
_dragBorder.Visibility = Visibility.Visible;
bool found = false;
foreach (var dropElement in _dropElements.Where(x => x != _currentDragedElement))
{
if (!dropElement.IsLoaded)
{
dropElement.UpdateLayout();
dropElement.InvalidateArrange();
dropElement.InvalidateMeasure();
dropElement.InvalidateVisual();
continue;
}
//Point dropPoint = dropElement.TransformToAncestor(rootElement).Transform(new Point(0, 0));
Point dropPoint = dropElement.PointToScreen(new Point(0, 0));
Rect dropRect = new Rect(dropPoint, new Size(dropElement.ActualWidth, dropElement.ActualHeight));
Rect dragRect = new Rect(Canvas.GetLeft(_dragBorder), Canvas.GetTop(_dragBorder), _dragBorder.Width / 2, _dragBorder.Height);
Point mousePoint = rootElement.PointToScreen(Mouse.GetPosition(rootElement));
if (dropRect.IntersectsWith(new Rect(mousePoint, new Size(1, 1))))
{
SetIsDraggableOver(dropElement, true);
foreach (var drop in _dropElements.Where(x => x != dropElement))
{
SetIsDraggableOver(drop, false);
}
_currentDropElement = dropElement;
found = true;
}
else
{
SetIsDraggableOver(dropElement, false);
}
}
if (!found)
{
_currentDropElement = null;
}
}
else
{
DragEnded?.Invoke(_currentDragedElement, _currentDragedElement);
DropDraggable();
}
}
#endregion
#region Private Methods
/// <summary>
/// Registers a framework element as a draggable element.
/// </summary>
/// <param name="element">The element.</param>
private static void RegisterDraggable(FrameworkElement element)
{
if (!_dragElements.Contains(element))
{
_dragElements.Add(element);
element.PreviewMouseDown += Draggable_PreviewMouseDown;
element.MouseMove += Draggable_MouseMove;
element.PreviewMouseUp += Draggable_PreviewMouseUp;
element.Unloaded += Element_Unloaded;
}
}
/// <summary>
/// Unregisters a framework element as a draggable element.
/// </summary>
/// <param name="element">The element.</param>
private static void RegisterDroppable(FrameworkElement element)
{
if (!_dropElements.Contains(element))
{
_dropElements.Add(element);
element.Unloaded += Element_Unloaded1;
}
}
/// <summary>
/// Registers a framework element as a droppable element.
/// </summary>
/// <param name="element">The element.</param>
private static void UnRegisterDraggable(FrameworkElement element)
{
_dragElements.Remove(element);
}
/// <summary>
/// Unregisters a framework element as a droppable element.
/// </summary>
/// <param name="element">The element.</param>
private static void UnRegisterDroppable(FrameworkElement element)
{
_dropElements.Remove(element);
}
/// <summary>
/// Creates the dragging element replication.
/// </summary>
private static void CreateDraggingElement()
{
if (_currentDragedElement != null)
{
BitmapSource source = UIHelper.TakeSnapshot(_currentDragedElement);
_dragBorder = new Border();
var surface = GetDraggingSurface(_currentDragedElement);
_dragBorder.Background = GetDraggableBackground(_currentDragedElement);
_dragBorder.BorderThickness = new Thickness(1);
_dragBorder.BorderBrush = GetDraggableBorderBrush(_currentDragedElement);
//dragBorder.CornerRadius = new CornerRadius(currentDragedElement.BorderRadius);
_dragBorder.Visibility = Visibility.Hidden;
_dragBorder.IsHitTestVisible = false;
_dragBorder.Width = source.PixelWidth;
_dragBorder.Height = source.PixelHeight;
_dragBorder.Opacity = GetDraggableOpacity(_currentDragedElement);
Image img = new Image();
_dragBorder.Child = img;
img.Stretch = System.Windows.Media.Stretch.Fill;
img.Source = source;
ScaleTransform scale = new ScaleTransform(1, 1, 0.5, 0.5);
_dragBorder.RenderTransformOrigin = new Point(0.5, 0.5);
_dragBorder.RenderTransform = scale;
surface.Children.Add(_dragBorder);
DoubleAnimation ani = new DoubleAnimation(0.95, new Duration(TimeSpan.FromMilliseconds(300)));
ani.AutoReverse = true;
ani.RepeatBehavior = RepeatBehavior.Forever;
DoubleAnimation aniOp = new DoubleAnimation(_dragBorder.Opacity, 0.5, new Duration(TimeSpan.FromMilliseconds(300)));
aniOp.AutoReverse = true;
aniOp.RepeatBehavior = RepeatBehavior.Forever;
scale.BeginAnimation(ScaleTransform.ScaleXProperty, ani);
scale.BeginAnimation(ScaleTransform.ScaleYProperty, ani);
_dragBorder.BeginAnimation(ContentControl.OpacityProperty, aniOp);
}
}
/// <summary>
/// Removes the dragging element replication.
/// </summary>
private static void RemoveDraggingElement()
{
if (_dragBorder != null)
{
_dragBorder.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, null);
_dragBorder.RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, null);
_dragBorder.BeginAnimation(ContentControl.OpacityProperty, null);
}
var surface = GetDraggingSurface(_currentDragedElement);
surface.Children.Clear();
}
/// <summary>
/// Drops the draggable.
/// </summary>
/// <param name="noDrop">if set to <c>true</c> [no drop].</param>
private static void DropDraggable(bool noDrop = false)
{
_isMouseDown = false;
RemoveDraggingElement();
_dragTimer.Stop();
SetIsDragging(_currentDragedElement, false);
foreach (var dropElement in _dropElements)
{
SetIsDraggableOver(dropElement, false);
}
if (noDrop)
{
_currentDragedElement = null;
_currentDropElement = null;
return;
}
if (_currentDropElement != null && _currentDragedElement != null)
{
_currentDropElement.RaiseEvent(new DropEventArgs(DropEvent, _currentDragedElement, _currentDropElement, _mouseDownLocation));
_currentDragedElement = null;
_currentDropElement = null;
}
else if (_currentDropElement == null && _currentDragedElement != null)
{
//if (DroppedNoWhere != null) DroppedNoWhere(this, currentDragedElement.Element);
//TODO: ??
}
}
#endregion
#region Draggable Event Handlers
/// <summary>
/// Handles the PreviewMouseDown event of the Draggable control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
private static void Draggable_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.Source != sender) return;
FrameworkElement element = sender as FrameworkElement;
if (!_dragElements.Exists(x => x == element))
{
e.Handled = false;
return;
}
_mouseDownLocation = e.GetPosition(element);
_currentDragedElement = element;
_isMouseDown = true;
}
/// <summary>
/// Handles the MouseMove event of the Draggable control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
private static void Draggable_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (_isMouseDown)
{
FrameworkElement element = _currentDragedElement;
if (element != null)
{
var surface = GetDraggingSurface(element);
if (surface != null)
{
if ((e.GetPosition(element).X > _mouseDownLocation.X + MIN_DRAG_OFFSET || e.GetPosition(element).X < _mouseDownLocation.X - MIN_DRAG_OFFSET) || (e.GetPosition(element).Y > _mouseDownLocation.Y + MIN_DRAG_OFFSET || e.GetPosition(element).Y < _mouseDownLocation.Y - MIN_DRAG_OFFSET))
{
element.ReleaseMouseCapture();
surface.ReleaseMouseCapture();
_isMouseDown = false;
CreateDraggingElement();
_dragTimer.Start();
SetIsDragging(element, true);
}
}
}
}
}
/// <summary>
/// Handles the PreviewMouseUp event of the Draggable control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
private static void Draggable_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
FrameworkElement element = _currentDragedElement;
if (element != null)
{
if ((e.GetPosition(element).X > _mouseDownLocation.X + 10 || e.GetPosition(element).X < _mouseDownLocation.X - 10) || (e.GetPosition(element).Y > _mouseDownLocation.Y + 10 || e.GetPosition(element).Y < _mouseDownLocation.Y - 10))
{
DropDraggable();
}
else
{
DropDraggable(true);
}
}
}
/// <summary>
/// Handles the Unloaded event of the Element control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private static void Element_Unloaded(object sender, RoutedEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
UnRegisterDraggable(element);
}
#endregion
#region Droppable Event Handlers
/// <summary>
/// Handles the Unloaded1 event of the Element control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private static void Element_Unloaded1(object sender, RoutedEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
UnRegisterDroppable(element);
}
#endregion
}
}
|