1
votes

I'm developing a Xamarin Forms application that needs a ListView with CustomCells 'MyCustomCell'. Cells have a moderate number of bindings (9) and each cell is largely similar so I decided to set the caching strategy to RecycleElement. This list could contain 100 items easily. Each cell contains two images with an Uri source.

I usually bind the view's attributes in my MyCustomCell.xaml, for example with an Image:

<Image
    x:Name="MyImage"
    Source="{Binding ImageSource}"
    .../>

But I recently read this article https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance and I was wondering what are the main differences between binding in my MyCustomCell.xaml and in the overrode method 'OnBindingContextChanged' like this:

protected override void OnBindingContextChanged()
{
    base.OnBindingContextChanged();
    var item = BindingContext as MyModel;
    MyImage.Source = ImageSource.FromUri(item.ImageSource);
}

I tested both solutions and the second one seemed faster to me. Am I right ? What are the real differences between these two solutions ?

1

1 Answers

0
votes

I worked with optimization for ListView on my project, and I also read this topic. I can't answer on your question about OnBindingContext, but for speed up your listview you should check CachingStrategy. It's a really power :)
But 1st example better than 2nd, because logic in OnBindingContext is not the best practices.
You should follow to MVVM for for clean and understandable code and solution.