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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Accessing items in headertemplate from code behind

Thread ID:





131680 Jul 23,2017 12:44 PM UTC Jul 24,2017 10:51 AM UTC Xamarin.Forms 1
Tags: SfListView
Asked On July 23, 2017 12:44 PM UTC

Why SfListView requires a datatemplate for header?

<Label x:Name="lblName" />

For example Xamarin Forms ListView doesnt require


Problem here is if I have label like above, I cannot access it from code behind directly like lblName.Text="Test";, however in XF listView it is possible to do this. Can you please let me know what is the difference and how can I achieve this?

Dinesh Babu Yadav [Syncfusion]
Replied On July 24, 2017 10:51 AM UTC

Hi Emil, 
Thank you for contacting Syncfusion support. 
We would like to let you know that you need to define the custom view in the DataTemplate only for HeaderItem and this is the actual behavior in SfListView. Also, the reported requirement “Accessing Header item in code behind in SfListView” can be achieved by using binding concept. In the sample, you need to have a property in the ViewModel class and bind it to the custom view in the HeaderTempate as like below code snippet with Mode as “TwoWay”. So, whenever you change the property at runtime, the desired data gets updated in header item as expected. 
Code Example[XAML]: 
<listView:SfListView x:Name="listView" ItemSize="70" HeaderSize="50" 
                     ItemsSource="{Binding Contactsinfo}"> 
      <Grid BackgroundColor="Teal"> 
        <Label Text="{Binding HeaderText,Mode=TwoWay}" TextColor="White" 
               FontSize="18" LineBreakMode="NoWrap"/> 
Code Example[C#]: 
public string headertext; 
public string HeaderText 
  get { return headertext; } 
    headertext = value; 
public ContactsViewModel() 
   headertext = "SfListView Header"; 
   contactsinfo = new ObservableCollection<Contacts>(); 
Code Example[C#]: 
private void headerchanged_Clicked(object sender, EventArgs e) 
  ViewModel.HeaderText = "Contacts Header"; 
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 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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