Search code examples
c#uwpitemscontrol

How do I get the total height of all items inside an ItemsControl?


I've tried accessing rendersize, actualheight, height, nothing is providing height of all items inside my ItemsControl element - in fact the only property returning a value is ItemsControl.ActualHeight; however this is returning the same size as the parent StackPanel element, which is nested inside a grid.

Is there any way to calculate or pull the full height of an ItemsControl element with all Items generated/rendered? Currently if my window renders at 1920x1080 and I've got a ton of items in my ItemsControl - the ItemsControl actualHeight always matches the windows height; I need to be able to determine the full length of all my items and how it compares to the window size.

Thanks really appreciate your time and assistance!


Solution

  • ItemsControls are complicated entities, you see, there is progressive/incremental loading built in to those controls, it is part of a system called Virtualization, and it an extremely widespread across all UI systems, when you scroll down on BinGooglGo image results you get progressive loading for example.

    Not all items inside the ItemSource are rendered at the same time, instead only what the user sees have a 'physical' form.

    It is often for example that, A typical UWP ListView will only render the exact amount of items that fit into the current ViewPort (visible area) plus about 10-20 more items south and north of of the viewport in preparation of a scrolling action.

    Edit: But because i dont like leaving my answers not being solutions, i will showcase the following albeit Anti-Pattern :

    Wrap your ItemsControl with a Scrollviewer, it will cause an immediate load of all of its contents.