Hi
I need to get element from canvas by given point.
For example I have Rectangle on Canvas, which CanvasLeft and CanvasTop values are setted to some values.
I whant get element from canvas which CanvasLeft and CanvasTop vaules are for example 10 and 40.
Is it possible?
Thanks.
views:
17answers:
2
+2
A:
You can find the elements a specific position by using the VisualTreeHelper. It has a method FindElementsInHostCoordinates. You'll have to give it a host, for example the canvas and the coordinates and it returns a list of UIElements.
Here's the info on MSDN: http://msdn.microsoft.com/en-us/library/cc838402(v=VS.95).aspx
Sorskoot
2010-08-13 11:26:59
+2
A:
Code like this should do it:-
UIElement elem = VisualTreeHelper.FindElementsInHostCoordinates(new Point(10, 40), myCanvas).FirstOrDefault();
AnthonyWJones
2010-08-13 11:45:41