Data Templates

Customizing the appearance of data

PDF for offline use
Sample Code:

Let us know how you feel about this


0/250

last updated: 2016-03

A DataTemplate is used to specify the appearance of data on supported controls, and typically binds to the data to be displayed.

Introduction

Xamarin.Forms data templates provide the ability to define the presentation of data on supported controls. This article provides an introduction to data templates, examining why they are necessary.

Creating a DataTemplate

Data templates can be created inline, or in a ResourceDictionary. An inline template should be used if there's no need to reuse the data template elsewhere. Alternatively, a DataTemplate can be defined as a control-level, page-level, or application-level resource. This article demonstrates both techniques.

Creating a DataTemplateSelector

A DataTemplateSelector can be used to choose a DataTemplate at runtime based on the value of a data-bound property. This enables multiple DataTemplate instances to be applied to the same type of object in order to customize the appearance of select objects. This article demonstrates how to create and consume a DataTemplateSelector.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.