Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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) ?
- Host: GitHub
- URL: https://github.com/syncfusionexamples/json-listview-xamarin
- Owner: SyncfusionExamples
- Created: 2020-03-05T12:57:37.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-28T13:18:12.000Z (8 months ago)
- Last Synced: 2024-05-29T02:13:16.048Z (8 months ago)
- Topics: json, json-data, listview, xamarin, xamarin-forms
- Language: C#
- Homepage:
- Size: 519 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
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();
}
}
```