Getting the coordinates of a specific ListViewItem relative to it's owning ListView

681 views Asked by At

I'm trying to determine the physical coordinates (specifically I'm interested in the TOP and BOTTOM) of the container which represents the ListViewItem.

I have a reference to the ListViewItem via:

 ListViewItem item = ((ListView)AdornedElement).ItemContainerGenerator.ContainerFromIndex(idx) as ListViewItem;
 ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(item);   

I now need to take the item and figure out what it's top and bottom values are relative to the entire listview. This is for showing a dragline indicator during a drag drop.

Can anyone offer any insight?

Thanks

1

There are 1 answers

0
tronious On

For someone who this may help in the future. I figured this out (literally right after I posted)

    Point pointTransformToVisual = lvItem.TransformToVisual((Visual)theListView.Parent).Transform(new Point());

    Rect boundsRect = VisualTreeHelper.GetDescendantBounds(lvItem);
    boundsRect.Offset(transform.X, transform.Y);