Добавлен example

This commit is contained in:
2026-01-25 07:56:35 +03:00
parent a902474345
commit 33abd94f6e
20 changed files with 1052 additions and 1 deletions

View 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;
}
}