将以往的代码复制到代码库
This commit is contained in:
106
Future.Contract/Adorners/DragDropAdorner.cs
Normal file
106
Future.Contract/Adorners/DragDropAdorner.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Future.Contract
|
||||
{
|
||||
/// <summary>
|
||||
/// 拖动辅助装饰器
|
||||
/// </summary>
|
||||
public class DragDropAdorner : Adorner
|
||||
{
|
||||
#region 静态变量区
|
||||
private static DragDropAdorner sAdorner; //装饰器:拖放过程中所有效果绘制使用的装饰器对象,结束后会释放
|
||||
private static AdornerLayer sLayer; //装饰层:用于放置拖放效果装饰器,拖放过程结束后会清除对象引用
|
||||
|
||||
private static UIElement sOrigin; //拖起目标:被拖动的源对象
|
||||
private static UIElement sTarget; //放置目标:在拖动过程中用于放置拖动源的目标,随拖动过程而变化
|
||||
|
||||
private static Canvas sCanvas; //拖放画布:整个拖放过程的完整区域,是拖起目标与放置目标的祖辈
|
||||
private static Border sShadow; //鼠标拖起阴影:用于将托起目标尺寸按照相同缩放比缩放后变成阴影
|
||||
private static Canvas sEffect; //鼠标拖动效果:用于提示放置的参考点位置,左、上、右、下,中。
|
||||
|
||||
private static Dock sPosition; //参考放置位置:为放置目标的位置提供参考,左、上、右、下,中。
|
||||
|
||||
/// <summary>
|
||||
/// 放置的参考点
|
||||
/// </summary>
|
||||
public static Dock DropPosition { get => sPosition; }
|
||||
#endregion
|
||||
#region 静态方法区
|
||||
/// <summary>
|
||||
/// 设定完整拖放效果区域以及被拖动的对象,或是等效对象来起动拖放事件
|
||||
/// </summary>
|
||||
/// <param name="area">完整的拖放区域,必须是拖起目标与放置目标的共同祖先节点</param>
|
||||
/// <param name="origin">被拖动的可视化目标,或是其等效目标</param>
|
||||
/// <returns></returns>
|
||||
public static DragDropEffects DoDragDrop(UIElement area, UIElement dragSource, object data, DragDropEffects allowedEffects)
|
||||
{
|
||||
DragDropEffects dragDropEffects = allowedEffects;
|
||||
//TODO:准备拖放,生成阴影,监听拖动执行区域中的拖动事件
|
||||
dragDropEffects = DragDrop.DoDragDrop(dragSource, data, dragDropEffects);
|
||||
//TODO:拖拽操作完成,释放装饰器以及过程中使用的所有资源
|
||||
sLayer.Remove(sAdorner);
|
||||
return dragDropEffects;
|
||||
}
|
||||
|
||||
private static void OnDragEnter(UIElement target, DragEventArgs args)
|
||||
{
|
||||
sTarget= target;
|
||||
target.MouseMove += Target_MouseMove;
|
||||
//TODO:更换目标对象,监听目标对象的鼠标事件,规制“阴影”与“效果”
|
||||
}
|
||||
|
||||
private static void Target_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
|
||||
{
|
||||
//TODO:计算鼠标位置,移动效果与阴影
|
||||
}
|
||||
//public static void OnDragOver(UIElement target, DragEventArgs args)
|
||||
//{
|
||||
// //TODO:计算鼠标位置,移动效果与阴影
|
||||
//}
|
||||
public static void OnDragLeave(UIElement target, DragEventArgs args)
|
||||
{
|
||||
//TODO:清除目标对象,清除对鼠标事件的监听,清除“阴影”与“效果”
|
||||
target.MouseMove -= Target_MouseMove;
|
||||
}
|
||||
public static void DropCompleted(UIElement target, DragEventArgs args)
|
||||
{
|
||||
//TODO:清除静态存储区中所使用过的数据,清除装饰器
|
||||
}
|
||||
#endregion
|
||||
private readonly VisualCollection mVisuals;
|
||||
private DragDropAdorner(UIElement adornedElement) : base(adornedElement)
|
||||
{
|
||||
mVisuals = new VisualCollection(this);
|
||||
sCanvas = new Canvas
|
||||
{
|
||||
Background=Brushes.Transparent
|
||||
};
|
||||
|
||||
mVisuals.Add(sCanvas);
|
||||
sLayer = AdornerLayer.GetAdornerLayer(adornedElement);
|
||||
sLayer?.Add(this);
|
||||
}
|
||||
|
||||
protected override int VisualChildrenCount => mVisuals.Count;
|
||||
|
||||
protected override Visual GetVisualChild(int index) => mVisuals[index];
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
//var bubbleSize = _bubble.DesiredSize;
|
||||
//var location = new Point(finalSize.Width + 10, (finalSize.Height - bubbleSize.Height) / 2);
|
||||
//_bubble.Arrange(new Rect(location, DesiredSize));
|
||||
sCanvas.Arrange(new Rect(new Point(), finalSize));
|
||||
return finalSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user