46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using Lattice.Core.DragDrop.Abstractions;
|
|
using Lattice.Core.DragDrop.Models;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Lattice.Example.DragDrop;
|
|
|
|
public class CustomDropHandler : IDropTarget
|
|
{
|
|
private readonly Action<object> _onDrop;
|
|
|
|
public CustomDropHandler(Action<object> onDrop)
|
|
{
|
|
_onDrop = onDrop;
|
|
}
|
|
|
|
public async Task<bool> CanAcceptDropAsync(DropInfo dropInfo, CancellationToken cancellationToken = default)
|
|
{
|
|
// Принимаем только объекты типа DragDropItem
|
|
return dropInfo.Data is DragDropItem;
|
|
}
|
|
|
|
public async Task OnDragOverAsync(DropInfo dropInfo, CancellationToken cancellationToken = default)
|
|
{
|
|
if (dropInfo.Data is DragDropItem)
|
|
{
|
|
dropInfo.SuggestedEffects = Core.DragDrop.Enums.DragDropEffects.Copy;
|
|
dropInfo.ShowVisualFeedback = true;
|
|
}
|
|
}
|
|
|
|
public async Task OnDropAsync(DropInfo dropInfo, CancellationToken cancellationToken = default)
|
|
{
|
|
if (dropInfo.Data is DragDropItem item)
|
|
{
|
|
_onDrop(item);
|
|
dropInfo.MarkAsHandled();
|
|
}
|
|
}
|
|
|
|
public Task OnDragLeaveAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
} |