locked
Color Binding Android Behaviour RRS feed

  • Question

  • User351456 posted

    Hello,

    I've created a listview of colors by iterating though the color object to get all the field names, I then bind the observablecollction to the listview and use a color converter to convert the color names to a valid color. This all works correctly and displays fine on iOS, however on Android the first 9 box views have the correct background color, but after that all the box view background are white.

    There doesn't seem to be any warning or errors, and i'm confused as it's rendering correctly on iOS, has anyone ever came across a problem like this before? Thanks.

    Sample of the binding below

    <ListView x:Name="colorList" SeparatorVisibility="None" ItemsSource="{Binding Colors}"  SelectedItem="{Binding SelectedColor, Mode=TwoWay}">  
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <Grid>
                                        <BoxView BackgroundColor="{Binding ., Mode=TwoWay,Converter={StaticResource colorConverter}}"/>
                                    </Grid>
                                 </ViewCell>
                             </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>  
    
    Sunday, September 22, 2019 10:16 PM

Answers

  • User369979 posted

    I found it could be the CachingStrategy's issue after testing. It seems your circumstance needs to be applied to RecycleElement: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance#recycleelement

    • Each cell has a small to moderate number of bindings.
    • Each cell's BindingContext defines all of the cell data.
    • Each cell is largely similar, with the cell template unchanging.

    And it runs well when I change the CachingStrategy. You could test my sample from the attachment.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, September 23, 2019 2:33 AM

All replies

  • User369979 posted

    I found it could be the CachingStrategy's issue after testing. It seems your circumstance needs to be applied to RecycleElement: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance#recycleelement

    • Each cell has a small to moderate number of bindings.
    • Each cell's BindingContext defines all of the cell data.
    • Each cell is largely similar, with the cell template unchanging.

    And it runs well when I change the CachingStrategy. You could test my sample from the attachment.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, September 23, 2019 2:33 AM
  • User351456 posted

    @LandLu Thank you for that , it was the caching strategy!

    Tuesday, September 24, 2019 9:16 AM