Skip to content

Commit cc202e3

Browse files
author
saravanan.ayyanar
committed
How to customize tree nodes using data template selector in wpf treeview?
1 parent ecd4553 commit cc202e3

38 files changed

+1671
-0
lines changed

TemplateSelector/App.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup useLegacyV2RuntimeActivationPolicy="true">
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
5+
6+
</startup>
7+
</configuration>

TemplateSelector/App.ico

4.19 KB
Binary file not shown.

TemplateSelector/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="NodeWithImageDemo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:NodeWithImageDemo"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

TemplateSelector/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace NodeWithImageDemo
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.UI.Xaml.TreeView.Engine;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
10+
namespace NodeWithImageDemo
11+
{
12+
class ItemTemplateSelector : DataTemplateSelector
13+
{
14+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
15+
{
16+
var treeviewNode = item as TreeViewNode;
17+
if (treeviewNode == null)
18+
return null;
19+
if (treeviewNode.Level == 0)
20+
return Application.Current.MainWindow.FindResource("headerTemplate") as DataTemplate;
21+
else
22+
return Application.Current.MainWindow.FindResource("descriptionTemplate") as DataTemplate;
23+
}
24+
}
25+
}
784 Bytes
Loading
579 Bytes
Loading
49.4 KB
Loading
54.2 KB
Loading
1.39 KB
Loading

0 commit comments

Comments
 (0)