Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo Detatch -> Detach in DropTargetAdorner corrected #505

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading