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. Image for the cookie policy date

Creating a DataTemplate as external XAML file

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

5 Replies

DB Dinesh Babu Yadav Syncfusion Team May 24, 2017 07:22 AM

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 
 



VS Valeriano Simeone May 24, 2017 09:49 AM

Hi,
your support is great!

Regards,
Valeriano Simeone


DB Dinesh Babu Yadav Syncfusion Team May 24, 2017 11:16 PM

Hi Valeriano, 
 
Thanks for your feedback. 
 
Regards, 
Dinesh Babu Yadav 



LS Liviu Sosu January 12, 2021 05:15 AM

I have alos found this thread very useafull. Thank you Valeriano for asking and Syncfusion for answering.


LN Lakshmi Natarajan Syncfusion Team January 12, 2021 05:50 AM

Hi Liviu, 
 
Thank you for your feedback.  
 
Regards, 
Lakshmi Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon