Determine the position of a ListboxItem in a canvas?

In my WPF application, I have a canvas with a list in it. I want to overlay the Listboxitem on another control after it clicks on the element. But for this I need the Listboxitem position in the canvas. I see the problem because the only element is not a child of the canvas. Only the Listbox itself.

Is there a way to get the relative position of the ListboxItem in the canvas, or maybe the absolute position inside the window?

+3
source share
2 answers

try this code:

Point p = listboxItem.TranslatePoint(new Point(0.0,0.0),Window.GetWindow(listboxItem));

To get it relative to the canvas, replace the new point with the canavas location.

NTN.

+3
source

, , WPF Adorner , .

0

Source: https://habr.com/ru/post/1705262/