문제

If I have a virtualizingstackpanel inside of my scrollviewer then how does my scrollviewer know what height the scrollbar needs to be?

For example if I have 10,000 items how does it know that I have only scrolled 5 percent down the list?

What if I do not know the size of the items?

도움이 되었습니까?

해결책

this is a really good resource, at the bottom you can download a sample project. I think what you are looking for is in the GetFirstVisibleIndex and GetLastVisibleIndex functions. I've listed them below for convenience. Basically you'll have an offset tracking how far the 'top' of your list is. that combined with the size of the items will help get to the values you are looking for

 private int GetFirstVisibleIndex()
 {
    return (int)Math.Floor(_offset.Y / _itemSize.Height);
 }

 private int GetLastVisibleIndex()
 {
    return Math.Min((int)Math.Ceiling((_offset.Y + _viewport.Height) / _itemSize.Height) - 1, GetItemsCount() - 1);
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top