我自己画的一个图形,我想实现拖放 是否可行?在线等
我自己画的一个图形,我想实现拖放 是否可行?在线等
谢谢
[解决办法]
轻松+简单. 容器是一个Canvas ,拖拽的是一个自定义UC
private void Carrier_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = Carrier;
e.Mode = ManipulationModes.All;
}
private void Carrier_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
FrameworkElement element = e.Source as FrameworkElement;
Matrix matrix = (element.RenderTransform as MatrixTransform).Matrix;
var deltaManipulation = e.DeltaManipulation;
Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
center = matrix.Transform(center);
#region 处理缩放手势
matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
#endregion
#region 处理旋转手势
matrix.RotateAt(deltaManipulation.Rotation, center.X, center.Y);
#endregion
#region 处理移动手势
matrix.Translate(deltaManipulation.Translation.X, deltaManipulation.Translation.Y);
#endregion
(element.RenderTransform as MatrixTransform).Matrix = matrix;
}
private void Carrier_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
}
void Carrier_TouchDown(object sender, TouchEventArgs e)
{
FrameworkElement element = e.Source as FrameworkElement;
Canvas.SetZIndex(element, 2); //将元素的层次设置为2
SetZIndex(element, Carrier);
}
public void SetZIndex(FrameworkElement element, Canvas canvas)
{
foreach (FrameworkElement fe in canvas.Children)
{
if (fe != element && !fe.Name.Equals("btnExit"))
{
Canvas.SetZIndex(fe, 1);
}
}
}