Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/syncfusionexamples/xamarin-datasource-getting-started

Demo application shows to create a sample using Xamarin.Forms DataSource.
https://github.com/syncfusionexamples/xamarin-datasource-getting-started

datasource xamarin xamarin-forms

Last synced: 27 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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.
```C#
using Syncfusion.DataSource;

public App()
{
DataSource dataSource = new DataSource();
dataSource.Source = new ContactsList();
}
```
Create a data model to bind it to the DisplayItems.
```C#
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.

```C#
public class ContactsList : ObservableCollection, 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 ##

* [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/) or [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/).
* Xamarin add-ons for Visual Studio (available via the Visual Studio installer).

## 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.