To determine if it’s odd or even, we take a look at the item source of the ListView and determine what the index of our item is. container: the container that holds our items, in our case the ListView.item: holds the object that is in the cell that we render.Then in the OnSelectTemplate, we write the logic to select which template the ListView has to show for the incoming item. Notice how it has two properties that take a DataTemplate, these can be dynamically assigned to our selector. Let’s start with defining the DataTemplateSelector. Let me show you how to use the DataTemplateSelector to implement an alternate row color mechanism in the ListView. All the details can be seen in the documentation, which is found here: Implementing alternate row color This can be used to mimic a Facebook or Twitter timeline for instance where you want to view some different types of content in one list. Then, simply assign the DataTemplateSelector to your ListView, and it will show you different cells based on your logic. In this method, you can write whatever logic is needed to determine which template should be selected. You simply define a couple of templates, create a class that inherits from the DataTemplateSelector and then override the abstract method in there. We will see what this looks like in code a little bit later on. With a DataTemplateSelector, you can add logic to what template is to be used based on conditions that you determine. The code for this post is found on my GitHub: DataTemplateSelector In this post, I will do a quick write-up of the details. But I thought I would implement it with a DataTemplateSelector. Of course, multiple solutions are available. When browsing on StackOverflow today, I came across a question that was asking how to set an alternate row color on a ListView.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |