SfListView doesn't trigger events such as BindingContextChanged or Appearing on its cells?


I'm using SfListView (16.1.0.24) in Xamarin.Forms, displaying a cell `MyCellDataTemplate` that inherits from `ViewCell`. I've created overrides for `OnBindingContextChanged()` and `OnAppearing()` in the `MyCellDataTemplate` class, but they're never called. If I use the same class on a standard ListView, they are called.

Is this a bug in SfListView, or do I need to do something special to get them to trigger?

Thanks.



3 Replies

MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 26, 2018 12:22 PM UTC

Hi Dave, 
 
We would like to let you know that SfListView is implemented completely based on Virtualization and Item recycling concept by default. So it creates elements only which are in the view on initial loading and while scrolling, we have recycled the existing elements by updating only the BindingContext to provide better performance on scrolling. 
 
So you can achieve your requirement by hooking the BindingContextChanged event for the View in your custom ViewCell and perform the necessary actions as like below code example. 
 
Code Example[C#]: 
public partial class MyCellDataTemplate: ViewCell 
{ 
  public TestViewCell() 
  { 
    InitializeComponent(); 
    this.View.BindingContextChanged += View_BindingContextChanged; 
  } 
 
  private void View_BindingContextChanged(object sender, EventArgs e) 
  { 
    //custom action here 
  } 
} 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 



DW Dave Wood February 26, 2018 08:51 PM UTC

Thanks, that kind of works.

     private void View_BindingContextChanged(object sender, EventArgs e) {
          //get model
          Grid grid = sender as Grid;
          if (grid == null) { return; }
          Model model = grid.BindingContext as Model;
          if (model == null) { return; }

          //custom action here
     } 

So this lets us get the model/item that's being displayed.

Hooking into the SizeChanged event lets us get the layout info.

Thanks a lot!



MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 27, 2018 04:02 AM UTC

Hi Dave, 
 
Thanks for the update. 
 
Regards, 
G.Muthu kumaran. 


Loader.
Up arrow icon