This repository describes how to customize the style of tree nodes based on its level using converter in WPF TreeView (SfTreeView).
The TreeView allows you to customize the style of TreeViewItem based on different levels by using IValueConverter.
<Window.Resources>
<local:FontAttributeConverter x:Key="FontAttributeConverter"/>
</Window.Resources>
<Window.DataContext>
<local:MailFolderViewModel x:Name="viewModel"/>
</Window.DataContext>
<Grid>
<Syncfusion:SfTreeView HorizontalAlignment="Left" ItemTemplateDataContextType="Node" ItemsSource="{Binding Folders}" ChildPropertyName="SubFolder" >
<Syncfusion:SfTreeView.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Content.FolderName}" FontWeight="{Binding Level, Converter={StaticResource FontAttributeConverter}}"
FontSize="14"/>
</DataTemplate>
</Syncfusion:SfTreeView.ItemTemplate>
</Syncfusion:SfTreeView>
</Grid>public class FontAttributeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var level = (int)value;
return level == 0 ? FontWeights.Bold : FontWeights.Regular;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}