From f16cbcc6920a8de52974c782e2c518b06c4bbb41 Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Fri, 22 Aug 2025 17:11:27 +0530 Subject: [PATCH] ES-975464 - Resolve the ReadMe issue in this sample repository --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d41781..66b59a0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,59 @@ -# How to customize tree nodes using data template selector in wpf treeview? -This repository describes how to customize tree nodes using data template selector in wpf treeview +# How to customize tree nodes using data template selector in WPF TreeView + +This repository describes how to customize tree nodes using data template selector in [WPF TreeView](https://www.syncfusion.com/wpf-controls/treeview) (SfTreeView) + +The TreeView allows you to customize the appearance of each item with different templates based on specific constraints by using the [ItemTemplateSelector](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeView.SfTreeView.html#Syncfusion_UI_Xaml_TreeView_SfTreeView_ItemTemplateSelector). You can choose a [DataTemplate](https://docs.microsoft.com/en-us/dotnet/api/system.windows.datatemplate?view=netcore-3.1) for each item at runtime based on the value of data-bound property using `ItemTemplateSelector`. + +#### XAML + +``` xml + + + + + + + + + + + + + + + + + + +``` + +#### C# + +``` csharp +class ItemTemplateSelector : DataTemplateSelector +{ + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + var treeviewNode = item as TreeViewNode; + if (treeviewNode == null) + return null; + if (treeviewNode.Level == 0) + return Application.Current.MainWindow.FindResource("RootTemplate") as DataTemplate; + else + return Application.Current.MainWindow.FindResource("ChildTemplate") as DataTemplate; + } +} +``` \ No newline at end of file