Adding a DataTemplate to the global resource dictionary

Now let's get back to the App.xaml file. Since we require a custom cell in our ListView on the StocklistPage, we are going to create a DataTemplate in the global resource dictionary. DataTemplate can be created in two ways, as an inline template or in a resource dictionary. There is no better method, it's more on personal preference. In our example, we are going to be creating ours in a resource dictionary.

Open up the App.xaml file and insert the DataTemplate in the resource dictionary like this:

 <DataTemplate x:Key="ListItemTemplate"> <ViewCell> <StackLayout Margin="20, 15, 20, 5"> <Label x:Name="NameLabel" Text="{Binding Name}"/> <Label x:Name="CategoryLabel" Text="{Binding Category}"/> ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.