Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/syncfusionexamples/json-listview-xamarin

This repository contains the sample about how to bind JSON data to Xamarin.Forms ListView (SfListView) ?
https://github.com/syncfusionexamples/json-listview-xamarin

json json-data listview xamarin xamarin-forms

Last synced: 27 days ago
JSON representation

This repository contains the sample about how to bind JSON data to Xamarin.Forms ListView (SfListView) ?

Awesome Lists containing this project

README

        

# How to bind JSON data to xamarin.Forms ListView (SfListView) ?
You can bind the data from JSON (JavaScript Object Notation) file in Xamarin.Forms SfListView using the ItemsSource property.

**XAML**

The JSON data can be bound to the SfListView ItemsSource property.
``` xml

















```
**C#**

Accessed the JSON file from local folder and StreamReader reads the data to return as a dynamic object.
``` c#
public ViewModel()
{
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream(
"ListViewXamarin.Data.Data.json");
using (StreamReader sr = new StreamReader(stream))
{
var jsonText = sr.ReadToEnd();
ItemsSource = JsonConvert.DeserializeObject(jsonText);
}
}
```
**C#**

Dynamic object value converted by ExpandoObject to show the values.
``` c#
public class DynamicToPathValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return value;
ExpandoObject busniessObject = JsonConvert.DeserializeObject(value.ToString());
var jsonList = busniessObject.ToList();
if (parameter.Equals("Value1"))
return jsonList[0].Value;
if (parameter.Equals("Value2"))
return jsonList[1].Value;
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
```