Skip to content

Commit e2ac663

Browse files
Merge pull request #2 from Santhosh-SF4792/master
Update the README.md file
2 parents 2515860 + aff4549 commit e2ac663

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,86 @@
11
# -json-data-binding-for-.net-maui-treeview
2-
Explains about how to bind json data to .net maui treeview
2+
This repository demonstrates how to bind JSON data to the .NET MAUI TreeView (SfTreeView) control. It provides a sample implementation that downloads and deserializes hierarchical JSON data, maps it to data models, and binds it to the TreeView using the ItemsSource property for dynamic and structured data display.
3+
4+
## Sample
5+
The Syncfusion® .NET MAUI TreeView enables you to bind data from a JSON file using the ItemsSource property. This demonstration will guide you through the process of binding JSON Collection to the TreeView.
6+
7+
### XAML
8+
```xaml
9+
<ContentPage.BindingContext>
10+
<local:TreeViewViewModel x:Name="viewModel"/>
11+
</ContentPage.BindingContext>
12+
<syncfusion:SfTreeView x:Name="treeView" Margin="10"
13+
ItemTemplateContextType="Node"
14+
ItemsSource="{Binding JSONCollection}"
15+
ChildPropertyName="SubTaskDetails">
16+
<syncfusion:SfTreeView.Behaviors>
17+
<local:TreeViewBehavior/>
18+
</syncfusion:SfTreeView.Behaviors>
19+
</syncfusion:SfTreeView>
20+
```
21+
22+
### View Model
23+
```csharp
24+
public class TreeViewViewModel : INotifyPropertyChanged
25+
{
26+
private bool isDownloaded;
27+
private IList<TaskDetails> jsonCollection;
28+
29+
public event PropertyChangedEventHandler? PropertyChanged;
30+
#region Fields
31+
32+
public IList<TaskDetails> JSONCollection
33+
{
34+
get
35+
{
36+
return jsonCollection;
37+
}
38+
set
39+
{
40+
jsonCollection = value;
41+
OnPropertyChanged(nameof(JSONCollection));
42+
}
43+
}
44+
45+
public DataServices DataService { get; set; }
46+
47+
#endregion
48+
#region Constructor
49+
public TreeViewViewModel()
50+
{
51+
JSONCollection = new ObservableCollection<TaskDetails>();
52+
DataService = new DataServices();
53+
GenerateSource();
54+
}
55+
#endregion
56+
57+
#region Generate Source
58+
private async void GenerateSource()
59+
{
60+
isDownloaded = await DataService.DownloadJsonAsync();
61+
if (isDownloaded)
62+
{
63+
var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
64+
var fileText = File.ReadAllText(Path.Combine(localFolder, "Data.json"));
65+
66+
//Read data from the local path and set it to the collection bound to the ListView.
67+
JSONCollection = JsonConvert.DeserializeObject<IList<TaskDetails>>(fileText);
68+
}
69+
}
70+
71+
#endregion
72+
}
73+
```
74+
75+
## Requirements to run the demo
76+
77+
To run the demo, refer to [System Requirements for .NET MAUI](https://help.syncfusion.com/maui/system-requirements).
78+
79+
## Troubleshooting:
80+
### Path too long exception
81+
82+
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.
83+
84+
## License
85+
86+
Syncfusion® has no liability for any damage or consequence that may arise from using or viewing the samples. The samples are for demonstrative purposes. If you choose to use or access the samples, you agree to not hold Syncfusion® liable, in any form, for any damage related to use, for accessing, or viewing the samples. By accessing, viewing, or seeing the samples, you acknowledge and agree Syncfusion®'s samples will not allow you seek injunctive relief in any form for any claim related to the sample. If you do not agree to this, do not view, access, utilize, or otherwise do anything with Syncfusion®'s samples.

0 commit comments

Comments
 (0)