Localization in WPF TreeGrid (SfTreeGrid)

Localization is the process of translating the application resources into different language for the specific cultures. You can localize the treegrid by adding resource file. Application culture can be changed by setting CurrentUICulture before InitializeComponent method.

Below application culture changed to German.

public MainWindow()
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de");
    InitializeComponent();
}

Localize the drag and drop window text in treegrid

To localize the treegrid, drag and drop window based on CurrentUICulture using resource files, follow the below steps.

1.Create new folder and named as Resources in your application. 

2.Add the default resource file of treegrid into Resources folder. You can download the Syncfusion.SfGrid.WPF.resx here.

Default resouce file of WPF treegrid

3.Right-click on the Resources folder, select Add and then NewItem.

4.In Add New Item wizard, select the Resource File option and name the filename as Syncfusion.SfGrid.WPF.<culture name>.resx. For example, you have to give name as Syncfusion.SfGrid.WPF.de.resx for German culture.

5.The culture name that indicates the name of language and country.

Creating a resource file

6.Now, select Add option to add the resource file in Resources folder.

Adding the created resource file as resource

7.Add the Name/Value pair in Resource Designer of Syncfusion.SfGrid.WPF.de.resx file and change its corresponding value to corresponding culture.

Modifying the resource file as per culture

WPF treegrid drag and drop window displayed with localized text

You can download the sample here.

Localize when the resource file is present in different assembly or different namespace

By default, the treegrid try to read the resource file from executing assembly and its default namespace by using Assembly.GetExecuteAssembly method. When the resource file is located at different assembly or namespace, then you can let treegrid know by using GridResourceWrapper.SetResources method.

public MainWindow()
{
    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
    Syncfusion.UI.Xaml.Grid.GridResourceWrapper.SetResources("Assembly_name", "namespace_name");
    InitializeComponent();
}

Edit default culture resource

You can edit default resource file by adding it to Resources folder of your application where treegrid reads the static texts from here. You can download the default resource file from here.

Default resource file

Now, change the Name/Value pair in Resource Designer of Syncfusion.SfGrid.WPF.resx file.

Modifying the default resource file

WPF treegrid shown with modified resource