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.
This commit is contained in:
Steven Kirk
2025-10-01 10:32:24 +02:00
committed by GitHub
parent 9bf7abcdfe
commit 97b256f457
+82 -1
View File
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Avalonia.Input.Platform;
using Avalonia.Interactivity;
@@ -41,6 +42,86 @@ namespace Avalonia.Input
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>
/// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target.
/// <seealso cref="DataObject"/>