Skip to content

SyncfusionExamples/How-to-customize-the-style-of-tree-nodes-based-on-its-level-using-converter-in-wpf-treeview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to Customize the Style of Tree Nodes Based on its Level Using Converter in WPF TreeView?

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.

XAML

<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>

C#

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();
    }
}

Customized the tree node style based on the levels

About

This repository describes how to customize the style of tree nodes based on its level using converter in wpf treeview

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages