Skip to content

Commit ac7a765

Browse files
Merge pull request #1 from Santhosh-SF4792/main
Update the README.md file
2 parents 8751d4f + 6ac00d7 commit ac7a765

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
1-
**[View document in Syncfusion Xamarin Knowledge base](https://www.syncfusion.com/kb/12246/how-to-customize-the-item-template-in-an-unbound-xamarin-forms-treeview-sftreeview)**
1+
# customize-the-itemtemplate-unbound-treeview-xamarin
2+
3+
This repository demonstrates how to customize the item template in an unbound Xamarin.Forms TreeView (SfTreeView) control. It provides a sample implementation that shows how to define and style TreeView nodes directly in XAML without data binding, enabling flexible and visually distinct hierarchical layouts.
4+
5+
## Sample
6+
7+
### XAML
8+
```xaml
9+
<ContentPage.Resources>
10+
<ResourceDictionary>
11+
<helper:TextColorConverter x:Key="textColorConverter"/>
12+
</ResourceDictionary>
13+
</ContentPage.Resources>
14+
15+
<StackLayout>
16+
<syncfusion:SfTreeView x:Name="treeView">
17+
<syncfusion:SfTreeView.ItemTemplate>
18+
<DataTemplate>
19+
<Grid>
20+
<Label Text="{Binding Content}" TextColor="{Binding Level, Converter={StaticResource textColorConverter}}" VerticalOptions="Center"/>
21+
</Grid>
22+
</DataTemplate>
23+
</syncfusion:SfTreeView.ItemTemplate>
24+
25+
<syncfusion:SfTreeView.Nodes>
26+
<treeviewengine:TreeViewNode Content="Australia" IsExpanded="True">
27+
<treeviewengine:TreeViewNode.ChildNodes>
28+
<treeviewengine:TreeViewNode Content="New South Wales">
29+
<treeviewengine:TreeViewNode.ChildNodes>
30+
<treeviewengine:TreeViewNode Content="Sydney"/>
31+
<treeviewengine:TreeViewNode Content="Canberra"/>
32+
<treeviewengine:TreeViewNode Content="Newcastle–Maitland"/>
33+
</treeviewengine:TreeViewNode.ChildNodes>
34+
</treeviewengine:TreeViewNode>
35+
<treeviewengine:TreeViewNode Content="Victoria">
36+
<treeviewengine:TreeViewNode.ChildNodes>
37+
<treeviewengine:TreeViewNode Content="Melbourne"/>
38+
</treeviewengine:TreeViewNode.ChildNodes>
39+
</treeviewengine:TreeViewNode>
40+
</treeviewengine:TreeViewNode.ChildNodes>
41+
</treeviewengine:TreeViewNode>
42+
</syncfusion:SfTreeView.Nodes>
43+
</syncfusion:SfTreeView>
44+
</StackLayout>
45+
```
46+
47+
### TextColorConverter
48+
```csharp
49+
public class TextColorConverter : IValueConverter
50+
{
51+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
52+
{
53+
var level = (int)value;
54+
if (level == 0) return Color.Red;
55+
else if (level == 1) return Color.Blue;
56+
else return Color.Green;
57+
}
58+
59+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
60+
{
61+
throw new NotImplementedException();
62+
}
63+
}
64+
```
65+
66+
## Requirements to run the demo
67+
68+
To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements)
69+
70+
## Troubleshooting
71+
### Path too long exception
72+
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.

0 commit comments

Comments
 (0)