I have a silverlight control in which i am dynamically creating shapes on button click These shapes are draggable across the form. Now i want to get top and left postion of a control on dragging (mousemove). Ple开发者_JAVA技巧ase help
Taking a look at your question history I can think of two approaches. I suspect that the shape is simply being placed on a Canvas
and the MouseMove
of which you speak refers to an event handler you've attached to the Canvas
. On that basis then.
void Canvas_MouseMove(object sender, MouseEventArgs e)
{
Type currentType = e.OriginalSource.GetType();
// Make decisions based on value of currentType here
DependencyObject source = (DependencyObject)e.OriginalSource;
Point p = new Point(Canvas.GetLeft(source), Canvas.GetTop(source));
}
The more general solution is to use the TransformToVisual
approach. Something like:-
var transform = ((UIElement)e.OriginalSource).TransformToVisual(MyCanvas);
Point p = transform.Transform(Point(0,0));
精彩评论