1

I want to fill a ListView with items as long as they fit on the current page sothat I do not have to scroll. For this I want to add an item, check it's height and if it is too big to fit in the remaining space I want to remove it.

My questions are:

  1. Is there a smarter way to solve this?
  2. When to check the realized items height?

In Windows 8.1 the ListView control does not have an ItemRealized or ItemCreated event. So when to check the item's container size?

I try to get the size via

UIElement container = (UIElement)ItemsListView.ContainerFromItem(obj);
double height = container.DesiredSize.Height;

Thanks for your help!

Robin-Manuel Thiel
  • 2,206
  • 19
  • 26
  • Is the intention that you want to basically want a paginated collection (e.g. 100 items, show 10 items per page @ 10 pages), or do you explicitly just want one ListView? – Greg B Jul 18 '14 at 16:10
  • You are right, the intention is to implement paging. But my items can have different heights sothat it might happen that on the first page there are 3 items, on the second 5 items and so on... – Robin-Manuel Thiel Jul 18 '14 at 16:13
  • With different sizes, you'll probably need to manage your own active list/page in the View's code behind. The ActualHeight property will be useful for determining availalble container size and size of the items I would think. – kenny Jul 18 '14 at 17:13

1 Answers1

0

Unfortunately I don't believe there is a built-in solution for paginated collections, besides the TabControl, which is probably not what you want.

Pagination usually is something that should be done on the ViewModel/business side of things, so if you know the sizes of the objects ahead of time, you may be able to do something like this How to paginate an ObservableCollection? or MVVM paging & sorting, providing the view with the correct number of items.

If it needs to be more dynamic and flexible, this is a pretty good article about pagination using a WrapPanel as the ItemsPanel for an ItemsControl http://imduff.blogspot.com/2008/02/this-is-way-how-i-implemented-paging.html.

Community
  • 1
  • 1
Greg B
  • 416
  • 3
  • 12