Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

ListView Alternating Row Color

$
0
0

Trying to implement that each odd and even row of a listview has a different colors. I tried it with an IValueconverter, but I can't seem to bind it to the ListViewItem. I also read about triggers, but no success yet.

public class BackgroundConverter : IValueConverter
    {
        public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is int)) return null;
            int index = (int)value;

            if (index % 2 == 0)
                return Color.White;
            else
                return Color.Blue;
        }

And then in XAML:

...
<local:ListViewBackgroundConverter x:Key="bgColorPicker" />
...

...
BackgroundColor="{Binding ?, Converter={StaticResource bgColorPicker}}"
...

Any proper trigger or IValueConverter example would be awesome.


Viewing all articles
Browse latest Browse all 91519

Trending Articles