浏览代码

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.
Steven Kirk 2 周之前
父节点
当前提交
97b256f457
共有 1 个文件被更改,包括 82 次插入1 次删除
  1. 82 1
      src/Avalonia.Base/Input/DragDrop.cs

+ 82 - 1
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.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"/>