TalkingCode
TalkingCode

Reputation: 13557

Determine ListboxItem position in a canvas?

In my WPF Application I have a canvas with a Listbox in it. I want to overlay an Listboxitem with another control after it was clicked on the item. But for that I need the position of the Listboxitem in the canvas. I see the problem because the single Item is not child of the canvas. Only the Listbox itself is.

Is there any way I can get the relative position of the ListboxItem in the canvas or maybe the absolute position inside the window?

Upvotes: 5

Views: 2993

Answers (2)

Satumba
Satumba

Reputation: 880

try this code:

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

In order to get it relative to the canvas, replace the new Point to the canavas location.

HTH.

Upvotes: 5

Daniel Pratt
Daniel Pratt

Reputation: 12077

This is not a direct answer to your question, but I wonder if the Adorner concept of WPF may give you what you want.

Upvotes: 1

Related Questions