I´m binding a pretty huge collection of items to an ItemsControl. The ItemTemplate of the ItemsControl is set to a custom usercontrol rendering the data. The ItemControl is virtualized.
The problem now is that each usercontrol in the ItemsControl can become quite heigh. Its even possible that it becomes heigher than the actual screenheight. If that happens I´ve no chance to see the rest of the usercontrol because as soon as I scroll the next item in the collection is brought to the top of the screen and the only half shown item gets completly scrolled out of view. If I don´t use virtualization everything is obviously working fine.
Is there any way to get around this behavior and still be able to use virtualization?
There is a way around the behaviour, but it's not entirely pretty... basically, it's to implement your own virtualizing panel. As you correctly noticed, the behaviour of the built in panel is to draw from the top of the topmost item - you can't have half an item at the top of the screen. This, basically, is because it makes the virtualization code a lot lighter weight, and in most cases it's not a problem.
You can create your own panel (derive from VirtualizingPanel
) that doesn't have this restriction. It's not straightforward, but it's worthwhile for the results!
In your case, if all of the items are fixed size and beyond the size of the screen, you may find it's not quite so complicated - a lot of the complexity comes when items are variable sizes.