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

Creating a DataTemplate as external XAML file

Thread ID:

Created:

Updated:

Platform:

Replies:

130652 May 23,2017 08:50 PM UTC May 25,2017 04:16 AM UTC Xamarin.Forms 3
loading
Tags: SfListView
Valeriano Simeone
Asked On May 23, 2017 09:14 PM UTC

Hi,how can i set ItemTemplate to external XAML file?(without DataTemplateSelector class).thanksValeriano

Dinesh Babu Yadav [Syncfusion]
Replied On May 24, 2017 12:22 PM UTC

Hi Valeriano, 
 
Thank you for using Syncfusion Products. 
 
The reported requirement “Defining the ItemTemplate in external XAML file” can be achieved by ResourceDictionary and you can define the template in any file within the ResourceDictionary and access it by key which is defined for each template. Here, we have create the DataTemplate for ItemTemplate in the Resources dictionary of App.xaml file as like below code snippet and bind the Key to the ItemTemplate property in MainPage.xaml. 
 
Code Example[XAML]: 
  
App.XAML 
<Application.Resources> 
    <ResourceDictionary> 
      <DataTemplate x:Name="CustomTemplate" x:Key="CustomTemplate"> 
        <Grid x:Name="grid" RowSpacing="1"> 
 
       </Grid> 
      </DataTemplate> 
    </ResourceDictionary> 
  </Application.Resources> 
</Application> 
  
MainPage.XAML 
?xml version="1.0" encoding="utf-8" ?> 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:local="clr-namespace:ListViewSample;assembly=ListViewSample" 
             xmlns:listView="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" 
             xmlns:dataSource="clr-namespace:Syncfusion.DataSource;assembly=Syncfusion.DataSource.Portable" 
             x:Class="ListViewSample.MainPage"> 
  <ContentPage.BindingContext> 
    <local:ContactsViewModel x:Name="viewModel"/> 
  </ContentPage.BindingContext> 
 
  <ContentPage.Content> 
    <Grid> 
      <listView:SfListView x:Name="listView" ItemSize="70"  
                           ItemTemplate="{StaticResource CustomTemplate}" 
                           ItemsSource="{Binding Contactsinfo}"  
                           ItemSpacing="0,0,5,0">  
      </listView:SfListView> 
    </Grid> 
  </ContentPage.Content> 
</ContentPage> 
  
For you reference, we have attached the sample and you can download it from the below link. 
 
  
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 
 


Valeriano Simeone
Replied On May 24, 2017 02:49 PM UTC

Hi,
your support is great!

Regards,
Valeriano Simeone

Dinesh Babu Yadav [Syncfusion]
Replied On May 25, 2017 04:16 AM UTC

Hi Valeriano, 
 
Thanks for your feedback. 
 
Regards, 
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

;