This is a migrated thread and some comments may be shown as answers.

Custom localization through xaml

1 Answer 174 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sehe
Top achievements
Rank 1
Sehe asked on 22 Dec 2011, 12:31 AM
I have an application that has to run on multiple languages. The user can change the language on the fly at runtime. I really need a way to update the text in the group by header without reloading the entire gridview.

I have successfully set LocalizationManager.Manager to a new custom manager as below. The downside is that I have to reconstruct the gridview in code.


LocalizationManager.Manager = new TelerikGridViewCustomLocalizationManager();
 
...
 
class TelerikGridViewCustomLocalizationManager : LocalizationManager
    {
        public override string GetStringOverride(string key)
        {
            return MyLocalization.GetResource(key);
        }
    }


Is there any way to call an update or refresh on the gridview instead of creating a new one in code?

Thank you for the help.

Scott

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 22 Dec 2011, 08:56 AM
Hi Scott,

Indeed, the necessary thing to do is to recreate the grid once the language is changed. However, as you want to update only the string in the group panel, you can get the template of the grid and bind the text in the TextBlock-s inside. It could be something similar to:

<Border BorderBrush="{StaticResource GridView_GroupPanelInnerBorder}" BorderThickness="1" Background="{TemplateBinding Background}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name="panelText" FontSize="9.5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False"
                                   Margin="{TemplateBinding Padding}"
                                   Text="{Binding LocalizedStrings.GridViewGroupPanelText, Source={StaticResource CustomLocStrings}}"                              
                                   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                                                                                        
                        <TextBlock x:Name="panelTextGrouped" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False"
                                   Margin="{TemplateBinding Padding}"
                                   Text="{Binding LocalizedStrings.GridViewGroupPanelTopTextGrouped, Source={StaticResource CustomLocStrings}}"
                                   Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>                                                                     
                        <ItemsPresenter VerticalAlignment="Center"/>
                    </StackPanel>
                </Border>

The language could be changed as:
private void Button2_Click(object sender, RoutedEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-De");
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-De");
            ((CustomResources)this.Resources["CustomLocStrings"]).LocalizedStrings = new Localization_RadGridView_SL.Resources.Strings();
        }

I would recommend you to run through this article for further reference.
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Sehe
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or