Hello Xamarin folks,
I was wondering if its possible to draw the cells of a ListView with iterating background colors EG:
How could I change the cell BG color for odd and even rows ?
This is our sample code: Any suggestions?
AbsoluteLayout cellLayout = new AbsoluteLayout();
ViewCell cell;
ListView listView = new ListView
{
ItemsSource = sampleItem,
ItemTemplate = new DataTemplate(() =>
{
Label sampleLabel = new Label();
nameLabel.SetBinding(Label.TextProperty, "Name");
AbsoluteLayout.SetLayoutBounds(nameLabel, new Rectangle(100f, 18f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
cellLayout.Children.Add(nameLabel);
cell = new ViewCell()
{
View = new AbsoluteLayout
{
Children = { sampleLabel, }
}
};
// How could I change the cell BG color for odd and even rows ?
//cell.View.BackgroundColor = ????
return cell;
})
};
Example of a SampleViewModel
List<SampleViewModel> sampleItem = new List< SampleViewModel >
{
new SampleViewModel("Jon Doe"),
new SampleViewModel("Will Thompson"),
new SampleViewModel("Jon Doe"),
};
public SampleViewModel(string name) { this.Name = name; }
public string Name { private set; get; }
Any Help is greatly appreciated.. Thanks in advance...