Добавлен example
This commit is contained in:
46
Lattice.Example.DragDrop/Handlers/CustomDropHandler.cs
Normal file
46
Lattice.Example.DragDrop/Handlers/CustomDropHandler.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user