Get Vissible Items from Viewable Area
Hello folks, I'm creating a custom virtualizing panel (different from virtualizingstackpanel), and I've come across with one little issue:
I need to get the visible vertical items from the viewport of a scrollviewer, given the viewport Height, and vertical offset.
I know how to do it when all the childs of the panel are fixed size(e.g Size(50,50)), but when childs have different sizes this gets kind of complicated.
I have an initial algorithm that will do the trick, but as I mentioned before it is only for fixed size childs.
Basically I need to find the indexes for the first and last item in the viewport Height of the panel.
csharp Code:
//Child Size would vary in this case.
firstVisibleItemIndex = (int) Math.Floor(_offset.Y / ChildSize) * childrenPerRow;
lastVisibleItemIndex = (int) Math.Ceiling((_offset.Y + _viewport.Height) / ChildSize) * childrenPerRow - 1;
Thanks in advance.