All docs
21.2 (EAP/Beta)
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
The page you are viewing does not exist in version 1.1. This link will take you to the root page.

Lesson 1: Bind to Data

  • 3 minutes to read

The DXCollectionView component displays a collection of data items. This topic explains how to bind a collection view to a data source.

Create a New Application and Add a CollectionView

  1. Create a new Xamarin.Forms cross-platform solution (CollectionViewExample) and include the DevExpress CollectionView component.

    In the main project’s App.xaml.cs file, call the DevExpress.XamarinForms.CollectionView.Initializer.Init() method to prepare DevExpress CollectionView for use in the application.

    using Xamarin.Forms;
    namespace CollectionViewExample {
        public partial class App : Application {
            public App() {
                MainPage = new MainPage();

    In the iOS project’s AppDelegate.cs file, call the DevExpress.XamarinForms.CollectionView.iOS.Initializer.Init() method.

    using Foundation;
    using UIKit;
    namespace CollectionViewExample.iOS {
        public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate {
            public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
                LoadApplication(new App());
                return base.FinishedLaunching(app, options);
  2. In the MainPage.xaml file of the .NET Standard project that contains the shared code, use the dxcv prefix to declare a namespace and add a DXCollectionView instance to the content page:


Prepare a Model and View Model

Create the following classes:

  • Contact - The data source’s records are instances of this class. Its public properties (Name, Photo and Phone) are data source’s fields.
  • ViewModel - The Data property of this class returns a collection of Contact objects that is used as a data source for the DXCollectionView component in this example.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xamarin.Forms;

namespace CollectionViewExample {
    public class Contact {
        string name;
        public string Name {
            get =>;
            set {
       = value;
                if (Photo == null) {
                    string resourceName = "CollectionViewExample.Images." + value.Replace(" ", "_") + ".jpg";
                    if (!String.IsNullOrEmpty(resourceName))
                        Photo = ImageSource.FromResource(resourceName);

        public Contact(string name, string phone) {
            Name = name;
            Phone = phone;
        public ImageSource Photo { get; set; }
        public string Phone { get; set; }

    public class ViewModel : INotifyPropertyChanged {
        public List<Contact> Data { get; }
        public ViewModel() {
            Data = new List<Contact>() {
                new Contact("Nancy Davolio", "(206) 555-9857"),
                new Contact("Andrew Fuller", "(206) 555-9482"),
                new Contact("Janet Leverling", "(206) 555-3412"),
                new Contact("Margaret Peacock", "(206) 555-8122"),
                new Contact("Steven Buchanan", "(71) 555-4848"),
                new Contact("Michael Suyama", "(71) 555-7773"),
                new Contact("Robert King", "(71) 555-5598"),
                new Contact("Laura Callahan", "(206) 555-1189"),
                new Contact("Anne Dodsworth", "(71) 555-4444"),

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

Add contact photos to the solution. To do this, create the Images directory in the CollectionViewExample project with the shared code, and add image files with the Build Action property set to EmbeddedResource.

Embedded Images

Bind a CollectionView to Data

In the MainPage.xaml file:

  1. Set the ContentPage’s BindingContext to a ViewModel instance.
  2. Bind the DXCollectionView.ItemsSource property to the view model’s Data property.
  3. Use the DisplayMember property to specify the data source’s field whose values should be displayed as list items. The DisplayFormat allows you to format list items.
    <dxcv:DXCollectionView ItemsSource="{Binding Data}"
                           DisplayFormat="Contact: {0}">

DXCollectionView now displays a vertical list of items: values of the specified field (DisplayMember) in the bound data source formatted according to the DisplayFormat property.


The next lesson explains how customize the appearance of the DXCollectionView‘s items.