Skip to content

Commit c5ddce1

Browse files
authored
Merge pull request #505 from punker76/fix/typo
Typo Detatch -> Detach in DropTargetAdorner corrected
2 parents b0526b8 + e7e3ff0 commit c5ddce1

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/GongSolutions.WPF.DragDrop/DragDrop.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ private static void DragSourceDown(object sender, DragInfo dragInfo, InputEventA
470470
return;
471471
}
472472

473-
// If the sender is a list box that allows multiple selections, ensure that clicking on an
474-
// already selected item does not change the selection, otherwise dragging multiple items
473+
// If the sender is a list box that allows multiple selections, ensure that clicking on an
474+
// already selected item does not change the selection, otherwise dragging multiple items
475475
// is made impossible.
476476
if ((Keyboard.Modifiers & ModifierKeys.Shift) == 0
477477
//&& (Keyboard.Modifiers & ModifierKeys.Control) == 0 // #432
@@ -783,7 +783,7 @@ private static void DropTargetOnDragOver(object sender, DragEventArgs e, EventTy
783783
// If the target is an ItemsControl then update the drop target adorner.
784784
if (itemsControl != null)
785785
{
786-
// Display the adorner in the control's ItemsPresenter. If there is no
786+
// Display the adorner in the control's ItemsPresenter. If there is no
787787
// ItemsPresenter provided by the style, try getting hold of a
788788
// ScrollContentPresenter and using that.
789789
UIElement adornedElement;
@@ -1001,7 +1001,7 @@ private static DropTargetAdorner DropTargetAdorner
10011001
get => dropTargetAdorner;
10021002
set
10031003
{
1004-
dropTargetAdorner?.Detatch();
1004+
dropTargetAdorner?.Detach();
10051005
dropTargetAdorner = value;
10061006
}
10071007
}

src/GongSolutions.WPF.DragDrop/DropTargetAdorner.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace GongSolutions.Wpf.DragDrop
77
{
8+
using JetBrains.Annotations;
9+
810
public abstract class DropTargetAdorner : Adorner
911
{
1012
public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
@@ -14,8 +16,9 @@ public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
1416
this.IsHitTestVisible = false;
1517
this.AllowDrop = false;
1618
this.SnapsToDevicePixels = true;
17-
this.m_AdornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
18-
this.m_AdornerLayer.Add(this);
19+
this.adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
20+
// can be null but should normally not be null
21+
this.adornerLayer?.Add(this);
1922
}
2023

2124
public IDropInfo DropInfo { get; set; }
@@ -25,15 +28,20 @@ public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
2528
/// </summary>
2629
public Pen Pen { get; set; } = new Pen(Brushes.Gray, 2);
2730

28-
public void Detatch()
31+
public void Detach()
2932
{
30-
if (!m_AdornerLayer.Dispatcher.CheckAccess())
33+
if (this.adornerLayer is null)
34+
{
35+
return;
36+
}
37+
38+
if (!this.adornerLayer.Dispatcher.CheckAccess())
3139
{
32-
m_AdornerLayer.Dispatcher.Invoke(this.Detatch);
40+
this.adornerLayer.Dispatcher.Invoke(this.Detach);
3341
return;
3442
}
3543

36-
this.m_AdornerLayer.Remove(this);
44+
this.adornerLayer.Remove(this);
3745
}
3846

3947
internal static DropTargetAdorner Create(Type type, UIElement adornedElement, IDropInfo dropInfo)
@@ -42,9 +50,11 @@ internal static DropTargetAdorner Create(Type type, UIElement adornedElement, ID
4250
{
4351
throw new InvalidOperationException("The requested adorner class does not derive from DropTargetAdorner.");
4452
}
53+
4554
return type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) })?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
4655
}
4756

48-
private readonly AdornerLayer m_AdornerLayer;
57+
[CanBeNull]
58+
private readonly AdornerLayer adornerLayer;
4959
}
5060
}

0 commit comments

Comments
 (0)