0

I have created a listview which has children whose background is bound to itemssource.

This works well on Android with the PropertyChanged event called.

But unfortunately it doesn't work as smooth on iOS the background change gets reflected only after I've scrolled the element out of view and back into the view to redraw it.

Is there any other way I can make the content refresh manually?

Code:

<ListView x:Name="ListView" ItemsSource="{Binding ListSource}" RowHeight="50">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <ViewCell.View>
                <ContentView Padding="10" BackgroundColor="{Binding BackgroundColor}">
                  <Label Text="{Binding Name}" HorizontalOptions="Center" TextColor="White" />
                </ContentView>
              </ViewCell.View>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>

Handling the itemclick to change the background and remove the selecteditem.

ListView.ItemTapped += async (s, e) =>
{
    var list = ListSource;

    var listItem = list.First(c => c.Id == ((ListItem)e.Item).Id);

    listItem.Selected = !listItem.Selected;

    SelectListSource = list;

    ListView.SelectedItem = null;

};

Code in the model :

    public Boolean Selected
    {
        get
        {
            return _selected;
        }
        set
        {
            _selected = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("BackgroundColor"));
        }
    }                 

    public Color BackgroundColor
    {
        get
        {
            if (Selected)
                return Color.Black;
            else
                return Color.Blue
        }
    }
AbsoluteSith
  • 1,727
  • 19
  • 45
  • Forget to mention I've used the code from : https://stackoverflow.com/questions/25885238/xamarin-forms-listview-set-the-highlight-color-of-a-tapped-item/29137410#29137410 – AbsoluteSith Apr 27 '18 at 10:56

1 Answers1

0

Ok so I found a work around by using XFGloss.

Added Binding to the ViewCell with the help of this nuget.

<ViewCell xfg:CellGloss.BackgroundColor="{Binding BackgroundColor}">
AbsoluteSith
  • 1,727
  • 19
  • 45