From 1ff07228bc4cb27dbb6316cf5e971a0f707d4ffe Mon Sep 17 00:00:00 2001 From: Mykhailo Matviiv Date: Sun, 12 Jun 2016 14:45:43 +0300 Subject: [PATCH] Add possibility to control scrolling speed via setting ScrollDelay attached property. --- GongSolutions.Wpf.DragDrop/DragDrop.cs | 45 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/GongSolutions.Wpf.DragDrop/DragDrop.cs b/GongSolutions.Wpf.DragDrop/DragDrop.cs index 3cdba1c2..0f4674fe 100644 --- a/GongSolutions.Wpf.DragDrop/DragDrop.cs +++ b/GongSolutions.Wpf.DragDrop/DragDrop.cs @@ -1,6 +1,8 @@ using System; using System.Collections; using System.Linq; +using System.Net; +using System.Timers; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -333,7 +335,21 @@ public static void SetDragMouseAnchorPoint(UIElement target, Point value) target.SetValue(DragMouseAnchorPointProperty, value); } - public static IDragSource DefaultDragHandler + + public static readonly DependencyProperty ScrollDelayProperty = DependencyProperty.RegisterAttached( + "ScrollDelay", typeof(double), typeof(DragDrop), new PropertyMetadata(default(double))); + + public static void SetScrollDelay(DependencyObject element, double value) + { + element.SetValue(ScrollDelayProperty, value); + } + + public static double GetScrollDelay(DependencyObject element) + { + return (double) element.GetValue(ScrollDelayProperty); + } + + public static IDragSource DefaultDragHandler { get { @@ -932,7 +948,24 @@ itemsControl is TabControl e.Effects = DragDropEffects.None; } - Scroll(dropInfo.VisualTarget, e); + + if (_canScroll) + { + _canScroll = false; + Scroll(dropInfo.VisualTarget, e); + var interval = GetScrollDelay(m_DragInfo.VisualSource); + if (interval > 0) + { + _canScrollDelayTimer.Interval = interval; + _canScrollDelayTimer.Start(); + } + else + { + _canScroll = true; + } + + } + } private static void DropTarget_PreviewDrop(object sender, DragEventArgs e) @@ -1013,5 +1046,13 @@ private static DropTargetAdorner DropTargetAdorner private static object m_ClickSupressItem; private static Point _adornerPos; private static Size _adornerSize; + + private static bool _canScroll = true; + private static readonly Timer _canScrollDelayTimer = new Timer(); + + static DragDrop() + { + _canScrollDelayTimer.Elapsed += (sender, args) => _canScroll = true; + } } }