Question

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.

Was it helpful?

Solution

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

OTHER TIPS

Code like this should do it:-

 UIElement elem = VisualTreeHelper.FindElementsInHostCoordinates(new Point(10, 40), myCanvas).FirstOrDefault();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top