Browse Source

Add Add/Remove event handler methods to DragDrop. (#19739)

Attached events should follow the pattern of providing static `Add<event-name>Handler` and `Remove<event-name>Handler` methods, but `DragDrop` did not provide these.
pull/19722/head
Steven Kirk 4 months ago
committed by GitHub
parent
commit
97b256f457
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 83
      src/Avalonia.Base/Input/DragDrop.cs

83
src/Avalonia.Base/Input/DragDrop.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System;
using System.Threading.Tasks;
using Avalonia.Input.Platform; using Avalonia.Input.Platform;
using Avalonia.Interactivity; using Avalonia.Interactivity;
@ -41,6 +42,86 @@ namespace Avalonia.Input
interactive.SetValue(AllowDropProperty, value); interactive.SetValue(AllowDropProperty, value);
} }
/// <summary>
/// Adds a handler for the DragEnter attached event.
/// </summary>
/// <param name="element">The element to attach the handler to.</param>
/// <param name="handler">The handler for the event.</param>
public static void AddDragEnterHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.AddHandler(DragEnterEvent, handler);
}
/// <summary>
/// Removes a handler for the DragEnter attached event.
/// </summary>
/// <param name="element">The element to remove the handler from.</param>
/// <param name="handler">The handler to remove.</param>
public static void RemoveDragEnterHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.RemoveHandler(DragEnterEvent, handler);
}
/// <summary>
/// Adds a handler for the DragLeave attached event.
/// </summary>
/// <param name="element">The element to attach the handler to.</param>
/// <param name="handler">The handler for the event.</param>
public static void AddDragLeaveHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.AddHandler(DragLeaveEvent, handler);
}
/// <summary>
/// Removes a handler for the DragLeave attached event.
/// </summary>
/// <param name="element">The element to remove the handler from.</param>
/// <param name="handler">The handler to remove.</param>
public static void RemoveDragLeaveHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.RemoveHandler(DragLeaveEvent, handler);
}
/// <summary>
/// Adds a handler for the DragOver attached event.
/// </summary>
/// <param name="element">The element to attach the handler to.</param>
/// <param name="handler">The handler for the event.</param>
public static void AddDragOverHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.AddHandler(DragOverEvent, handler);
}
/// <summary>
/// Removes a handler for the DragOver attached event.
/// </summary>
/// <param name="element">The element to remove the handler from.</param>
/// <param name="handler">The handler to remove.</param>
public static void RemoveDragOverHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.RemoveHandler(DragOverEvent, handler);
}
/// <summary>
/// Adds a handler for the Drop attached event.
/// </summary>
/// <param name="element">The element to attach the handler to.</param>
/// <param name="handler">The handler for the event.</param>
public static void AddDropHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.AddHandler(DropEvent, handler);
}
/// <summary>
/// Removes a handler for the Drop attached event.
/// </summary>
/// <param name="element">The element to remove the handler from.</param>
/// <param name="handler">The handler to remove.</param>
public static void RemoveDropHandler(Interactive element, EventHandler<DragEventArgs> handler)
{
element.RemoveHandler(DropEvent, handler);
}
/// <summary> /// <summary>
/// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target. /// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target.
/// <seealso cref="DataObject"/> /// <seealso cref="DataObject"/>

Loading…
Cancel
Save