Get the first and last visible element of widows phone listbox
How i can get the first and last visible element of windows phone listbox.My requirement is to load the list items based on scrolling. More detail : I am using a longlist selector for displaying items. It contains two hierarchy of lists. One list is for displaying the header items and another is for displaying the grouped item. While initial loading i will get the title and the url’s for fetching the child items of list. So here i need to load this list items(children) based on scrolling. My list contains huge no of items because of this i adopted this method. Please any one share some ideas to implement this in my app.
Check out the Colin's solution.
Here is the relevant snippet:
VirtualizingStackPanel vsp = itemsControl.Descendants<VirtualizingStackPanel>() .First() as VirtualizingStackPanel; // iterate over each of the items in view int firstVisibleItem = (int)vsp.VerticalOffset; int visibleItemCount = (int)vsp.ViewportHeight;
I have used it before and it works. Please note that both properties are regular properties and not dependency properties. In case you want to bind to them.