Forum Xamarin.Forms

ListView - Add IsAlternate Property to ViewCell which is set by its parent ListView

MarkRadcliffeMarkRadcliffe NZMember ✭✭✭


Add IsAlternate Boolean Property to ViewCell in order to let developers set something to distinguish the trasition between rows

API Changes

Add IsAlternate Boolean property to the base of ViewCell.
The ListView would keep this property up to date when the list is filtered/modified in some way. This could be an overrideable function or a onproperty changed event which the cell can listen to.

Intended Use Case

Allow developer to know if the row is an alternate row, allow developer to shade the background or similar to differentiate rows from eachother.


Open · Last Updated


  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    That isn't hard to implement at the ItemsSource model level, and it allows more flexibility, like shading out items from top to bottom

  • MarkRadcliffeMarkRadcliffe NZMember ✭✭✭

    @StephaneDelcroix that doesn't match the pattern of MVVM, the presentation/styling of a view shouldn't come from the model, only the required data.. I am currently doing it from the model but it is a common property in other visual frameworks.

    For instance in kendo each second row in a grid would have the class ".k-alt" attached to it to allow shading etc between rows.

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    I would prefer to see each row having an index, as it's implemented in iOS. With the index, alternate properties and many other things become almost trivial.

  • MarkRadcliffeMarkRadcliffe NZMember ✭✭✭
    edited January 2017

    @DavidDancy - I had put that in my previous draft of this then clicked cancel! Yes that would also work for what I am asking for as it could just be Index % 2 to know if its alternate or not.

    I'll add that as an option in the main post.

    Edit: cannot edit main post to include this as it was added a while ago.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    I like the idea but would wanted to post that RowIndex would be better than IsAlternate. David was faster than me. :-)

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    I'd be happy with Index

  • MarkRadcliffeMarkRadcliffe NZMember ✭✭✭
    edited January 2017

    Ideally then there would also need to be some trigger on change, so there is either a virtual OnIndexChanged that can be overriden or make it a bindable property.

    Bindable property makes the most sense in XAML so that there can be data triggers etc.

  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭

    I prefer a general index property, to allow for more use cases. Alternating can easily be determined with a converter, would still be nice if it's integrated, but with lower priority.

Sign In or Register to comment.