Skip to content

Demo application shows to create a sample using Xamarin.Forms DataSource.

Notifications You must be signed in to change notification settings

SyncfusionExamples/xamarin-datasource-getting-started

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Xamarin DataSource

About the sample

Demo application shows to create a sample using Xamarin.Forms DataSource.

Create new BlankApp (Xamarin.Forms.Portable) application in Xamarin Studio or Visual Studio. Import the DataSource namespace Syncfusion.DataSource and set the source for the DataSource by using the DataSource.Source property. You can bind the DataSource.DisplayItems as ItemsSource for any data bound control.

using Syncfusion.DataSource;

public App()
{
    DataSource dataSource = new DataSource();
    dataSource.Source = new ContactsList();
}

Create a data model to bind it to the DisplayItems.

public class Contacts : INotifyPropertyChanged
{
    private string contactName;

    public Contacts(string name)
    {
        contactName = name;
    }

    public string ContactName
    {
        get { return contactName; }
        set
        {
            if (contactName != value)
            {
                contactName = value;
                this.RaisedOnPropertyChanged("ContactName");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisedOnPropertyChanged(string _PropertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(_PropertyName));
        }
    }
}

Create a model repository class with required number of data objects.

public class ContactsList : ObservableCollection<Contacts>, INotifyPropertyChanged
{
    public ContactsList()
    {
        foreach (var customerName in CustomerNames)
        {
            var contact = new Contacts(customerName);
            this.Add(contact);
        }
    }
    string[] CustomerNames = new string[] {
    "Kyle",
    "Gina",
    "Irene",
    "Katie",
    "Michael",
    "Oscar",
    "Ralph",
    "Torrey",
    "William",
    "Bill",
    "Daniel",
    "Frank",
    "Brenda",
    "Danielle",
    "Fiona",
    "Howard",
    "Jack",
    "Larry",
    };
}

Requirements to run the demo

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

About

Demo application shows to create a sample using Xamarin.Forms DataSource.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published