Reputation: 37
I have a few hundred elements within a listview, and I want to know which elements are on the screen and at what position. If I do a Canvas.getLeft()
it simply returns zero. I want to be able to transform the item closest to the middle of the screen so that it's bigger than the others.
Upvotes: 1
Views: 336
Reputation: 63317
If you want to get the screen coordinates of the top-left point of a ListViewItem
(or any Visual
), you can just use the method Visual.PointToScreen and pass in an empty Point:
var pointInScreen = yourListViewItem.PointToScreen(new Point());
Upvotes: 0
Reputation: 5059
If you wanted to get the position of your element relative to your Window
, you could do the following:
Point relativePos = yourElement
.TransformToAncestor(yourWindow)
.Transform(new Point(0, 0));
yourWindow
can be replaced with any parent visual that contains yourElement
- if, for example, you wanted the position relative to the ListView
, you could replace it with yourListView
, etc.
Upvotes: 2