How can I get element from given point on canvas?
-
28-09-2019 - |
문제
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.
해결책
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
다른 팁
Code like this should do it:-
UIElement elem = VisualTreeHelper.FindElementsInHostCoordinates(new Point(10, 40), myCanvas).FirstOrDefault();
제휴하지 않습니다 StackOverflow