Drastic.DragAndDrop.Maui 1.0.9

dotnet add package Drastic.DragAndDrop.Maui --version 1.0.9
NuGet\Install-Package Drastic.DragAndDrop.Maui -Version 1.0.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Drastic.DragAndDrop.Maui" Version="1.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Drastic.DragAndDrop.Maui --version 1.0.9
#r "nuget: Drastic.DragAndDrop.Maui, 1.0.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Drastic.DragAndDrop.Maui as a Cake Addin
#addin nuget:?package=Drastic.DragAndDrop.Maui&version=1.0.9

// Install Drastic.DragAndDrop.Maui as a Cake Tool
#tool nuget:?package=Drastic.DragAndDrop.Maui&version=1.0.9

NuGet Version License

Drastic.DragAndDrop.Maui

Drastic.DragAndDrop.Maui is a component for adding drag and drop views and overlay effects to a MAUI Window.

fun

How To Use

First, you need to create the overlay and add it to a Window instance. This can be done to an existing Window after it has been created, or in the Window itself with code you add.

 this.overlay = new DragAndDropOverlay(this, this.overlayElement);
this.overlay.Drop += (sender, e) => this.Drop?.Invoke(this, e);

this.AddOverlay(this.overlay);

You can also use the DragAndDropWindow to automatically add the overlay to a window. Either create your own DragAndDropWindow after your app has launched, or replace the following in App.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
    }

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new Drastic.DragAndDrop.Maui.DragAndDropWindow(new Drastic.DragAndDrop.Maui.DragElementOverlay(Color.FromRgba(225, 0, 0, .2))) { Page = new AppShell() };
    }
}

If you use DragAndDropWindow, you can get the reference to it from the page you're on, and respond to the Drop event.

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        var window = (DragAndDropWindow)this.GetParentWindow();
        window.Drop += Window_Drop;
    }

    private void Window_Drop(object? sender, DragAndDropOverlayTappedEventArgs e)
    {
        try
        {
            // Get the first path.
            if (e.Paths.Any())
            {
                this.DropImage.Source = ImageSource.FromFile(e.Paths[0]);
            }
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex);
        }
    }
}

If you're using the DragAndDropOverlay directly, you can attach to its Drop event.

Tips

MAUI already has Drag and Drop gestures for individual elements. If you wish, you can also use Drastic.DragAndDrop directly and subscribe to a MAUI Views PlatforView and add a DragAndDrop control to that.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.0 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst15.4 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 316 12/31/2022
1.0.8 273 12/27/2022
1.0.7 281 12/26/2022
1.0.6 289 12/25/2022
1.0.5 286 12/24/2022