0

我在 XAML 中有一个 imagecanvas。

 <Canvas Name="imgCanvas" >
                <Canvas.RenderTransform>
                    <CompositeTransform TranslateX="0" TranslateY="0" CenterX="0" CenterY="0"></CompositeTransform>
                </Canvas.RenderTransform>



            </Canvas>

在类构造函数中,我将拖动事件添加到此画布

   g = GestureService.GetGestureListener(imgCanvas);
            g.DragStarted += new EventHandler<DragStartedGestureEventArgs>(g_DragStarted);
            g.DragDelta += new EventHandler<DragDeltaGestureEventArgs>(g_DragDelta);
            g.DragCompleted += new EventHandler<DragCompletedGestureEventArgs>(g_DragCompleted);

现在在 1 次点击功能中,我正在动态创建图像,并添加为画布的子项

当点击事件完成时,我可以拖动该图像。

有什么办法可以让我使用保持类型功能..而不是使用点击,我可以使用保持和保持功能,而无需抬起鼠标,我可以拖动它。

我也尝试了 mouseleftbuttondown 和 mousemove 事件....但是在鼠标移动功能中我无法拖动它。

Ct.translateX+=e.GetPosition(layoutGrid).X;//not working

Ct.translateY+=e.GetPosition(layoutGrid).Y;

请以任何方式向我建议,以便我可以将图像添加到画布并能够一键拖动。

4

1 回答 1

0

You won't be able to do this in a single event as there are two very distinct actions you want to detect and respond to.

Firstly, don't use the Gestures from the Toolkit. They are deprecated and have performance/memory issues.

You should be able to do this with the mouse events. What you'll need to do:
- After mousedown, as long as there is very little movement and no mouse up in a short period, create the image.
- After the image is created, respond to mousemove events by updating the position of the image until there is a mouse up.

There are likely to be lots of fun edge cases to handle but I'm sure you'll find them. ;)

于 2013-03-21T18:13:19.367 回答