Sometimes, although suited to a very wide range of UI requirements, a ListView introduces more complexity than required, or simply doesn’t suit the purpose you’re trying to achieve. For example, I recently worked on a project that required a very specific looking UI similar to a “card view” on the main landing screen that a ListView just simply wasn’t playing nicely with and would have required more work than necessary to achieve something fairly simple, with no need for the performance gains of recycled views etc.

In this case, and something I’ve encountered several times, a Repeater control is far simpler on iOS to get working quickly if you’ve been given a design brief that requires any form of “accordion” or “expand/collapse” functionality (I’ll reserve my personal UI thoughts here but we all need to work with designers and don’t always have a choice).

This is where a repeating control comes in to play. A control that simply adds views one after another to the screen. This can then be wrapped in a ScrollView to get a list like effect if you need it or whatever you’re trying to achieve.

While the same result can be achieved with a ListView, often this is just faster to get a screen out because there’s no mucking around with custom row height handling or adding and removing of items in a list and worrying about platform specific things like animations etc.

I’ve seen dozens of different implementations of Repeaters for Xamarin.Forms people have shared online, however one thing that I’m very used to with ListView’s is using Data Template Selectors, to get a different view for the different view model types to easily build out views of similar but not identical data.

The part I like about this approach, is it’s very simple to break out different views to match their data type/view model and reuse things between different screens. I won’t go into the specifics of data template selectors in this article, but essentially the idea is to have a class that just says this view model should get this view.

So you can add your view models of different types like this:

And then using a simple template selector, determine which item should have which view:

Over the years I’ve refined a repeating control from something that was quite crude (and still really is) to something that can be interchanged easily with a ListView in XAML when developing UI’s. I’ve used this to get something done faster because of less working around a ListView’s functionality because UI has been designed in a way that the ListView wasn’t intended for, as well as to performance test things to see if it really is actually worth the effort of the ListView versus the simplicity of a repeater control.

This means with a few simple code changes, I can swap out the controls and see what suits the requirement better quickly. E.g.

ListView

Repeater

And then from there you have all your controls as stock standard XAML (or C#) controls that you can work on as individual views:

Here’s the complete code for the Repeater control (taken from a NuGet package I’ve previously made available, DarkIce.Toolkit.Core *, which you’re more than welcome to just add to your project and be done with it, but it’s always useful knowing what’s under the hood as well):

If you want the entire working example, please have a look here on GitHub.

* One day (hopefully soon) I’ll flesh out this NuGet library a bit more and add some documentation and make it available on GitHub. For now it’s just something I’ve been using to get a bunch of common functionality I’ve written for various apps and often use quickly when I get into a new project.