We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

OnBindingContextChanged method not called in ViewCell

Thread ID:

Created:

Updated:

Platform:

Replies:

132940 Sep 29,2017 06:53 AM UTC Oct 2,2017 05:43 AM UTC Xamarin.Forms 1
loading
Tags: SfListView
Mynca Petrova
Asked On September 29, 2017 06:53 AM UTC

Hi,
I'm having a situation where the onBindingContextChanged method is not called in a ViewCell used in the Syncfusion sfListView through a DataTemplateSelector.
When I use the regular Xamarin.Forms ListView (commented in code below) the OnBindingContextChanged method is called and everything works fine.

Page with sfListView (binding is done by means of a ViewModel):

<syncfusion:SfListView     
    
ItemsSource="{Binding DataList}"
     ItemTemplate="{StaticResource TotalDataTemplateSelector}"
    
AutoFitMode="Height"
    
SelectionMode="None"
    
ItemSize="300">
</syncfusion:SfListView>


The used DataTemplateSelector:

public class TotalDataTemplateSelector : DataTemplateSelector

{

     private readonly DataTemplate _detailTotalDataTemplate;
     private readonly DataTemplate _generalTotalDataTemplate;

     public TotalDataTemplateSelector(bool expand)

       {

           _generalTotalDataTemplate = new DataTemplate(typeof(TotalTileViewCell));
          
_detailTotalDataTemplate = new DataTemplate(typeof(AccordionDetailTotalViewCell));

           _detailTotalDataTemplate.SetValue(AccordionDetailTotalViewCell.ExpandedProperty, expand);

       }

     protected override DataTemplate OnSelectTemplate(object item, BindableObject container)

       {

           if (item is GeneralTotal)
               retu
rn _generalTotalDataTemplate;

            

           if (item is DetailTotal)
               return _detailTotalDataTemplate;

       }

}


The ViewCell itself is just a regular Xamarin.Forms ViewCell with some stacklayout and labels in it. I need the OnBindingContextChanged method because these viewcell are dynamic and I have to take actions depending on the values of the binded object.


Any ideas why the OnBindingContextChanged method in the code behind of the ViewCell isn't called?
Thx



Dinesh Babu Yadav [Syncfusion]
Replied On October 2, 2017 05:43 AM UTC

Hi Peter, 
 
Thank you for using Syncfusion Products. 
 
In Xamarin Forms ListView, ViewCell has been internally handled to raise the OnBindingContextChanged event and override method whenever the binding context of item is changed. But in SfListView, we have updated the binding context of the ListViewItem only and it raises the View’s bindingcontext event if loaded in ViewCell  as like below code example in which you can dynamically modify the data for the item. 
 
Code Example[C#]: 
public IncomingViewCell() 
{ 
   InitializeComponent(); 
   this.View.BindingContextChanged += View_BindingContextChanged; 
} 
 
private void View_BindingContextChanged(object sender, EventArgs e) 
{ 
   //Modify the data here 
   var grid = sender as Grid; 
} 
 
For your reference, we have attached the sample and you can download it from the below link. 
 
 
Please let us know if you require further assistance. 
 
Dinesh Babu Yadav 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;