Created
August 2, 2018 08:28
-
-
Save jfversluis/e03664cc566840e1c64e0ee4c9caa5fb to your computer and use it in GitHub Desktop.
Grouped alternate color datatemplateselector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlternateColorDataTemplateSelector : DataTemplateSelector | |
{ | |
public DataTemplate EvenTemplate { get; set; } | |
public DataTemplate UnevenTemplate { get; set; } | |
private List<string> flatList; | |
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) | |
{ | |
if (flatList == null) | |
{ | |
var groupedList = (ObservableCollection<Grouping<string, string>>)((ListView)container).ItemsSource; | |
flatList = groupedList.SelectMany(group => group).ToList(); | |
} | |
return flatList.IndexOf(item as string) % 2 == 0 ? EvenTemplate : UnevenTemplate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment