Skip to content

Commit

Permalink
Merge pull request #505 from punker76/fix/typo
Browse files Browse the repository at this point in the history
Typo Detatch -> Detach in DropTargetAdorner corrected
  • Loading branch information
punker76 authored Dec 5, 2024
2 parents b0526b8 + e7e3ff0 commit c5ddce1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/GongSolutions.WPF.DragDrop/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ private static void DragSourceDown(object sender, DragInfo dragInfo, InputEventA
return;
}

// If the sender is a list box that allows multiple selections, ensure that clicking on an
// already selected item does not change the selection, otherwise dragging multiple items
// If the sender is a list box that allows multiple selections, ensure that clicking on an
// already selected item does not change the selection, otherwise dragging multiple items
// is made impossible.
if ((Keyboard.Modifiers & ModifierKeys.Shift) == 0
//&& (Keyboard.Modifiers & ModifierKeys.Control) == 0 // #432
Expand Down Expand Up @@ -783,7 +783,7 @@ private static void DropTargetOnDragOver(object sender, DragEventArgs e, EventTy
// If the target is an ItemsControl then update the drop target adorner.
if (itemsControl != null)
{
// Display the adorner in the control's ItemsPresenter. If there is no
// Display the adorner in the control's ItemsPresenter. If there is no
// ItemsPresenter provided by the style, try getting hold of a
// ScrollContentPresenter and using that.
UIElement adornedElement;
Expand Down Expand Up @@ -1001,7 +1001,7 @@ private static DropTargetAdorner DropTargetAdorner
get => dropTargetAdorner;
set
{
dropTargetAdorner?.Detatch();
dropTargetAdorner?.Detach();
dropTargetAdorner = value;
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/GongSolutions.WPF.DragDrop/DropTargetAdorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace GongSolutions.Wpf.DragDrop
{
using JetBrains.Annotations;

public abstract class DropTargetAdorner : Adorner
{
public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
Expand All @@ -14,8 +16,9 @@ public DropTargetAdorner(UIElement adornedElement, IDropInfo dropInfo)
this.IsHitTestVisible = false;
this.AllowDrop = false;
this.SnapsToDevicePixels = true;
this.m_AdornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
this.m_AdornerLayer.Add(this);
this.adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
// can be null but should normally not be null
this.adornerLayer?.Add(this);
}

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

public void Detatch()
public void Detach()
{
if (!m_AdornerLayer.Dispatcher.CheckAccess())
if (this.adornerLayer is null)
{
return;
}

if (!this.adornerLayer.Dispatcher.CheckAccess())
{
m_AdornerLayer.Dispatcher.Invoke(this.Detatch);
this.adornerLayer.Dispatcher.Invoke(this.Detach);
return;
}

this.m_AdornerLayer.Remove(this);
this.adornerLayer.Remove(this);
}

internal static DropTargetAdorner Create(Type type, UIElement adornedElement, IDropInfo dropInfo)
Expand All @@ -42,9 +50,11 @@ internal static DropTargetAdorner Create(Type type, UIElement adornedElement, ID
{
throw new InvalidOperationException("The requested adorner class does not derive from DropTargetAdorner.");
}

return type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) })?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
}

private readonly AdornerLayer m_AdornerLayer;
[CanBeNull]
private readonly AdornerLayer adornerLayer;
}
}

0 comments on commit c5ddce1

Please sign in to comment.