简体   繁体   中英

How to use Localization Extensions for Multi Language for DataGrid Columns in the Header

I'm writing a program with multi-language support and using the localization extension. In a label, button, or textbox everything performs correctly. Only the headers of a data grid don't perform correctly. With the following code

DataGridTextColumn Header="{lex:Loc name}" IsReadOnly="True" Binding="{Binding Name}" Width="Auto"

only the Key appears on the surface.

Greetings and thanks for the help.

                            <DataGridTextColumn IsReadOnly="True" Binding="{Binding LastName}" Width="Auto" SortDirection="Ascending">
                                <DataGridTextColumn.Header>
                                    <TextBlock Text="{lex:Loc Global_Lastname}"/>
                                </DataGridTextColumn.Header>
                            </DataGridTextColum

This works, but it is cumbersome....

I know it's a bit late for the answer but I just stumbled upon the exact same problem today so here is my solution.

<DataGridColumn 
 Header="{lex:Loc Namespace.Of.The.ResourceFile:NameOfTheResourceFile:Global_Lastname}"
 IsReadOnly="True"
 Width="Auto"
 Binding="{Binding Name}" />

But there's a catch, the actual namespace of the resource file was:

Namespace.Of.The.ResourceFile.Resources.NameOfTheResourceFile

So I needed to remove the "Resource" part in the namespace and put the name of the resource file after the ':' for the lex:Loc to work. I have absolutely no idea why this works like this but for the future dev looking for this answer, I hope it'll help you. And if anyone can give a proper explanation, that would be greatly appreciated !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM