You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

DragnDrop

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

DragnDrop

Minimal Drag and Drop Service UI library

1.0.0
unpublished
nugetNuGet
Maintainers
1
Source

Avalonia Dragging Service

A lightweight, cross-platform drag-and-drop interaction service for AvaloniaUI, designed for flexibility and extensibility.
Supports multiple independent or nested instances, complex drop precedence, and custom drag/drop logic via callbacks.

Compatible with Avalonia 11+ and .NET 8.0+

✨ Features

  • Multiple independent instances within the same visual tree
  • Nested instance support with inner precedence resolution
  • Overlap-aware drop target and dragged control resolution, prioritizing deeper controls
  • Custom drag/drop callbacks via attached properties (AllowDrag, AllowDrop)
  • Pointer-aware drag context: includes full PointerEventArgs and dragged control set
  • Dynamic service management via IDisposable pattern
  • XAML/Binding-ready: Easy to integrate via attached properties
  • Cross-platform: Fully compatible with all Avalonia-supported platforms

🛠️ How to Use

1. Mark a container (that inherits from Panel control) as the root of a drag instance

<StackPanel local:DraggingServiceAttached.IsRootOfDraggingInstance="True">

2. Enable Dragging/Dropping on your controls:

<Button Content="Drag me!"
        local:DraggingServiceAttached.AllowDrag="{Binding OnDragCallback}" />
<TextBlock Content="Drop on me!"
        local:DraggingServiceAttached.AllowDrag="{Binding OnDropCallback}" />

3. Implement the callbacks in your ViewModel (better for an MVVM approach) or code-behind:

void OnDragCallback(DraggingServiceCallbackArgs args) {
    // Access dragged controls and pointer info
    var controls = args.DraggedControls;
    var pointer = args.PointerEvent;
    // Logic here
}

void OnDropCallback(DraggingServiceCallbackArgs args) {
    // Access dragged controls and pointer info
    var controls = args.DraggedControls;
    var pointer = args.PointerEvent;
    // Logic here
}

Data can be read via the data-context of the dragged controls/drop targets for a better MVVM approach

4. Dispose the service when no longer needed by setting IsRootOfDraggingInstance property to false on the root control:

    control.SetValue(IsRootOfDraggingInstance, false)

or

    DraggingServiceAttached.SetIsRootOfDraggingInstance(control, false);

Notes:

  • The service sets a transparent Background if not present and enables the IsHitTestVisible property for every control used in the service.
  • Calling Dispose() on the actual instance will not work. Always set the IsRootOfDraggingInstance Attached Property to dispose the instance.
  • Each attached property can be set via XAML or code-behind, allowing for flexible integration.

Roadmap and improvements 🚧:

  • Add support for multiple dragged controls at the same time
  • Add options to tunneling or bubbling events for overlapped dragged controls or drop targets
  • Add support for dynamic visual tree changes
  • Add support for async callbacks

Keywords

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts