在 WP7 中,canvas.getleft 的图像返回 0 [英] canvas.getleft for image returns 0 in WP7
本文介绍了在 WP7 中,canvas.getleft 的图像返回 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取画布中的图像位置.但是 Canvas.GetLeft 和 Canvas.GetTop 总是返回 0,即使我在画布上拖动图像.这是下面的一段代码.
I m trying to get the image position in my canvas. But Canvas.GetLeft and Canvas.GetTop always return 0 even though I drag the image across the canvas. Here is the piece of code below.
private void MouseDragElementBehavior_DragFinished(object sender, MouseEventArgs e)
{
MessageBox.Show("Canvas Left Position" + Canvas.GetLeft(image1).ToString());
MessageBox.Show("Canvas Top Position" + Canvas.GetTop(image1)).ToString();
MessageBox.Show("Canvas Index" + Canvas.GetZIndex(image1));
}
请告诉我如何解决这个问题.
Please let me know how to solve this issue.
推荐答案
MouseDragElementBehavior 使用 MatrixTransformation,而不是画布的 top 和 left 属性.
The MouseDragElementBehavior uses a MatrixTransformation, not the canvas' top and left properties.
要检索位置,您可以尝试使用 MouseDragElementBehavior 的 X 和 Y 属性:
To retrieve the position, you can try using X and Y properties of the MouseDragElementBehavior:
private void MouseDragElementBehavior_DragFinished(object sender, MouseEventArgs e)
{
var behavior = (MouseDragElementBehavior)sender;
System.Diagnostics.Debug.WriteLine("Position: " + behavior.X + " / " + behavior.Y);
}
这篇关于在 WP7 中,canvas.getleft 的图像返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文