Skip to content

Commit 2e203bc

Browse files
authored
Merge pull request #424 from jizc/feature/enable-more-custom-implementations
Enable custom IDragInfo & IDropInfo implementations
2 parents 6c5f2c2 + 57c9116 commit 2e203bc

File tree

12 files changed

+30
-21
lines changed

12 files changed

+30
-21
lines changed

src/GongSolutions.WPF.DragDrop/DragDrop.Properties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ public static void SetSelectDroppedItems(DependencyObject element, bool value)
16141614
}
16151615

16161616
/// <summary>
1617-
/// Gets or sets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.
1617+
/// Gets or sets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.
16181618
/// </summary>
16191619
public static readonly DependencyProperty DropTargetScrollViewerProperty
16201620
= DependencyProperty.RegisterAttached("DropTargetScrollViewer",
@@ -1624,7 +1624,7 @@ public static readonly DependencyProperty DropTargetScrollViewerProperty
16241624

16251625
/// <summary>Helper for getting <see cref="DropTargetScrollViewerProperty"/> from <paramref name="element"/>.</summary>
16261626
/// <param name="element"><see cref="DependencyObject"/> to read <see cref="DropTargetScrollViewerProperty"/> from.</param>
1627-
/// <remarks>Gets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.</remarks>
1627+
/// <remarks>Gets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.</remarks>
16281628
/// <returns>DropTargetScrollViewer property value.</returns>
16291629
[AttachedPropertyBrowsableForType(typeof(UIElement))]
16301630
public static ScrollViewer GetDropTargetScrollViewer(DependencyObject element)
@@ -1635,7 +1635,7 @@ public static ScrollViewer GetDropTargetScrollViewer(DependencyObject element)
16351635
/// <summary>Helper for setting <see cref="DropTargetScrollViewerProperty"/> on <paramref name="element"/>.</summary>
16361636
/// <param name="element"><see cref="DependencyObject"/> to set <see cref="DropTargetScrollViewerProperty"/> on.</param>
16371637
/// <param name="value">DropTargetScrollViewer property value.</param>
1638-
/// <remarks>Sets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.</remarks>
1638+
/// <remarks>Sets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.</remarks>
16391639
[AttachedPropertyBrowsableForType(typeof(UIElement))]
16401640
public static void SetDropTargetScrollViewer(DependencyObject element, ScrollViewer value)
16411641
{

src/GongSolutions.WPF.DragDrop/DragDrop.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private static void DoMouseButtonDown(object sender, MouseButtonEventArgs e)
467467
DragSourceDown(sender, dragInfo, e, elementPosition);
468468
}
469469

470-
private static void DragSourceDown(object sender, DragInfo dragInfo, InputEventArgs e, Point elementPosition)
470+
private static void DragSourceDown(object sender, IDragInfo dragInfo, InputEventArgs e, Point elementPosition)
471471
{
472472
if (dragInfo.VisualSource is ItemsControl control && control.CanSelectMultipleItems())
473473
{
@@ -619,7 +619,7 @@ private static void DoDragSourceMove(object sender, Func<IInputElement, Point> g
619619
&& (Math.Abs(position.X - dragStart.X) > DragDrop.GetMinimumHorizontalDragDistance(dragInfo.VisualSource) ||
620620
Math.Abs(position.Y - dragStart.Y) > DragDrop.GetMinimumVerticalDragDistance(dragInfo.VisualSource)))
621621
{
622-
dragInfo.RefreshSelectedItems(sender);
622+
dragInfo.RefreshSourceItems(sender);
623623

624624
var dragHandler = TryGetDragHandler(dragInfo, sender as UIElement);
625625
if (dragHandler.CanStartDrag(dragInfo))
@@ -1040,7 +1040,7 @@ private static DropTargetAdorner DropTargetAdorner
10401040
}
10411041
}
10421042

1043-
private static DragInfo _dragInfo;
1043+
private static IDragInfo _dragInfo;
10441044
private static bool _dragInProgress;
10451045
private static object _clickSupressItem;
10461046

src/GongSolutions.WPF.DragDrop/DragInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public DragInfo(object sender, object originalSource, MouseButton mouseButton, F
197197
this.SourceItems ??= Enumerable.Empty<object>();
198198
}
199199

200-
internal void RefreshSelectedItems(object sender)
200+
/// <inheritdoc />
201+
public virtual void RefreshSourceItems(object sender)
201202
{
202203
if (sender is not ItemsControl itemsControl)
203204
{

src/GongSolutions.WPF.DragDrop/DropInfo.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,10 @@ public int UnfilteredInsertIndex
9696
/// <inheritdoc />
9797
public CollectionViewGroup TargetGroup { get; protected set; }
9898

99-
/// <summary>
100-
/// Gets the ScrollViewer control for the visual target.
101-
/// </summary>
99+
/// <inheritdoc />
102100
public ScrollViewer TargetScrollViewer { get; protected set; }
103101

104-
/// <summary>
105-
/// Gets or Sets the ScrollingMode for the drop action.
106-
/// </summary>
102+
/// <inheritdoc />
107103
public ScrollingMode TargetScrollingMode { get; set; }
108104

109105
/// <inheritdoc />

src/GongSolutions.WPF.DragDrop/DropTargetAdorner.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ internal static DropTargetAdorner Create(Type type, UIElement adornedElement, ID
5959
throw new InvalidOperationException("The requested adorner class does not derive from DropTargetAdorner.");
6060
}
6161

62-
return type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) })?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
62+
var ctor = type.GetConstructor(new[] { typeof(UIElement), typeof(IDropInfo) });
63+
if (ctor is null && dropInfo is DropInfo)
64+
{
65+
ctor = type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) });
66+
}
67+
68+
return ctor?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
6369
}
6470
}
6571
}

src/GongSolutions.WPF.DragDrop/DropTargetInsertionAdorner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GongSolutions.Wpf.DragDrop
99
{
1010
public class DropTargetInsertionAdorner : DropTargetAdorner
1111
{
12-
public DropTargetInsertionAdorner(UIElement adornedElement, DropInfo dropInfo)
12+
public DropTargetInsertionAdorner(UIElement adornedElement, IDropInfo dropInfo)
1313
: base(adornedElement, dropInfo)
1414
{
1515
}

src/GongSolutions.WPF.DragDrop/IDragInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,11 @@ public interface IDragInfo
119119
/// Gets the drag drop copy key state indicating the effect of the drag drop operation.
120120
/// </summary>
121121
DragDropKeyStates DragDropCopyKeyState { get; }
122+
123+
/// <summary>
124+
/// Refreshes the <see cref="SourceItems" /> property.
125+
/// </summary>
126+
/// <param name="sender">The drag source control.</param>
127+
void RefreshSourceItems(object sender);
122128
}
123129
}

src/GongSolutions.WPF.DragDrop/IDragInfoBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public interface IDragInfoBuilder
1919
/// <param name="mouseButton">The mouse button which was used for the drag operation.</param>
2020
/// <param name="getPosition">A function of the input event which is used to get drag position points.</param>
2121
[CanBeNull]
22-
DragInfo CreateDragInfo(object sender, object originalSource, MouseButton mouseButton, Func<IInputElement, Point> getPosition);
22+
IDragInfo CreateDragInfo(object sender, object originalSource, MouseButton mouseButton, Func<IInputElement, Point> getPosition);
2323
}
2424
}

src/GongSolutions.WPF.DragDrop/IDragSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IDragSource
1313
/// </summary>
1414
/// <param name="dragInfo">Object which contains several drag information.</param>
1515
/// <remarks>
16-
/// To allow a drag to be started, the <see cref="DragInfo.Effects" /> property on <paramref name="dragInfo" />
16+
/// To allow a drag to be started, the <see cref="IDragInfo.Effects" /> property on <paramref name="dragInfo" />
1717
/// should be set to a value other than <see cref="DragDropEffects.None" />.
1818
/// </remarks>
1919
void StartDrag(IDragInfo dragInfo);

src/GongSolutions.WPF.DragDrop/IDropInfoBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface IDropInfoBuilder
1717
/// <param name="dragInfo">Information about the drag source, if the drag came from within the framework.</param>
1818
/// <param name="eventType">The type of the underlying event (tunneled or bubbled).</param>
1919
[CanBeNull]
20-
IDropInfo CreateDropInfo(object sender, DragEventArgs e, [CanBeNull] DragInfo dragInfo, EventType eventType);
20+
IDropInfo CreateDropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo, EventType eventType);
2121
}
2222
}

0 commit comments

Comments
 (0)