Убраны синхронные методы
This commit is contained in:
@@ -2,45 +2,22 @@
|
||||
using Lattice.Core.Geometry;
|
||||
using Lattice.UI.DragDrop.Abstractions;
|
||||
using Lattice.UI.DragDrop.WinUI.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using System;
|
||||
|
||||
namespace Lattice.UI.DragDrop.WinUI.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Поставщик визуального представления для WinUI.
|
||||
/// </summary>
|
||||
public class WinUIDragVisualProvider : IDragVisualProvider
|
||||
{
|
||||
private readonly ResourceDictionary _resources;
|
||||
private DragAdorner? _currentAdorner;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализирует новый экземпляр класса <see cref="WinUIDragVisualProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="resources">Ресурсы для стилей.</param>
|
||||
public WinUIDragVisualProvider(ResourceDictionary resources)
|
||||
{
|
||||
_resources = resources ?? throw new ArgumentNullException(nameof(resources));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object CreateDragVisual(DragInfo dragInfo, Point initialPosition)
|
||||
{
|
||||
// Создаем новый DragAdorner
|
||||
// Создаем DragAdorner на основе данных
|
||||
_currentAdorner = new DragAdorner
|
||||
{
|
||||
DragData = dragInfo.Data,
|
||||
OpacityLevel = 0.8
|
||||
};
|
||||
|
||||
// Применяем стиль из ресурсов, если есть
|
||||
if (_resources.ContainsKey("DragAdornerStyle"))
|
||||
{
|
||||
_currentAdorner.Style = _resources["DragAdornerStyle"] as Style;
|
||||
}
|
||||
|
||||
// Настраиваем начальную позицию
|
||||
_currentAdorner.UpdatePosition(initialPosition);
|
||||
_currentAdorner.Show();
|
||||
@@ -48,7 +25,6 @@ public class WinUIDragVisualProvider : IDragVisualProvider
|
||||
return _currentAdorner;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void UpdateDragVisualPosition(object dragVisual, Point position)
|
||||
{
|
||||
if (dragVisual is DragAdorner adorner)
|
||||
@@ -57,31 +33,12 @@ public class WinUIDragVisualProvider : IDragVisualProvider
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void ReleaseDragVisual(object dragVisual)
|
||||
{
|
||||
if (dragVisual is DragAdorner adorner)
|
||||
{
|
||||
adorner.Hide();
|
||||
|
||||
// Отложенное удаление после анимации
|
||||
var timer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(150)
|
||||
};
|
||||
|
||||
timer.Tick += (s, e) =>
|
||||
{
|
||||
timer.Stop();
|
||||
if (adorner.Parent is Panel panel)
|
||||
{
|
||||
panel.Children.Remove(adorner);
|
||||
}
|
||||
};
|
||||
|
||||
timer.Start();
|
||||
_currentAdorner = null;
|
||||
}
|
||||
|
||||
_currentAdorner = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user