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

Changing DisplayName Language on the fly

9 Answers 219 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 03 Sep 2013, 11:12 AM
Hi, my problem is as follows; How can i bind the DisplayNames to my resources, so that language changes also effects them? using MVVM.
I can change the language of content in the property grid and everything around it with my CultureChangeEvent, but not the statically bound DisplayNames. Either I'd like them non-static or some way to update them as statics..
I have tried to get them in a non-static DataContext but failed, please help.

<telerik:RadPropertyGrid x:Name="SettingsPropertyGrid"
                         Item="{Binding Setting}"
                         SearchBoxVisibility="Collapsed"
                         SortAndGroupButtonsVisibility="Collapsed"
                         AutoGeneratePropertyDefinitions="False">
    <telerik:RadPropertyGrid.PropertyDefinitions>
        <telerik:PropertyDefinition Binding="{Binding Languages, Mode=TwoWay}"
                                    GroupName="Localization"
                                    DisplayName="{x:Static resx:SettingsModule_Resource.DisplayNameLanguage}"
                                    />
        <telerik:PropertyDefinition Binding="{Binding MeasurementUnit, Mode=TwoWay}"
                                    GroupName="Localization"
                                    DisplayName="{x:Static resx:SettingsModule_Resource.DisplayNameUnit}"
                                    />
        <telerik:PropertyDefinition Binding="{Binding DeviceId, Mode=TwoWay}"
                                    GroupName="Developer Settings"
                                    DisplayName="{x:Static resx:SettingsModule_Resource.DisplayNameDevice}"
                                    />
        <telerik:PropertyDefinition Binding="{Binding LogLevel, Mode=TwoWay}"
                                    GroupName="Developer Settings"
                                    DisplayName="{x:Static resx:SettingsModule_Resource.DisplayNameLog}"
                                    />
    </telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>


Asked the question in an old post, I probably shouldn't have done that..

//Anders

9 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 03 Sep 2013, 02:36 PM
Hi,

You can check our documentation here for more information on our localization mechanisms, especially the section about using ResourceManager. This online resource might also be helpful.

You will need to define resource files for the different languages so that when the language is changed to have the display value updated.
 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Andy
Top achievements
Rank 1
answered on 04 Sep 2013, 11:32 AM
OK, seems like the CustomLocalizationManager is a viable option for me.
Created the following class in my localization folder:

class CustomLocalizationManager : LocalizationManager
{
    public override string GetStringOverride(string key)
    {
        switch (key)
        {
            case "DisplayNameDevice":
                return SettingsModule_Resource.DisplayNameDevice;
 
            case "DisplayNameLanguage":
                return SettingsModule_Resource.DisplayNameLanguage;
 
            case "DisplayNameLog":
                return SettingsModule_Resource.DisplayNameLog;
 
            case "DisplayNameUnit":
                return SettingsModule_Resource.DisplayNameUnit;
        }
        return base.GetStringOverride(key);
    }
}

How do i bind to this? the only thing that doesn't change language in my settings module is this "DisplayName". With my current DisplayName Binding as shown in my previous post the language only changes after a restart of the application, i want it to change directly, w/o restart. "On the fly"!

Thanks!
//Anders
0
Accepted
Dimitrina
Telerik team
answered on 04 Sep 2013, 02:06 PM
Hi Anders,

You can set the ResourceKey similar to:
<telerik:PropertyDefinition... telerik:LocalizationManager.ResourceKey="DisplayName"/>
 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Pritesh
Top achievements
Rank 1
answered on 21 Oct 2015, 10:50 AM

Hi Telerik

This is not working for DisplayName of  telerik:PropertyDefinition but working for telerik:RadButton and other controls as well.

I would really appreciate if you can share a sample project/code for our reference.

Thanks

Pritesh Patel

0
Petya
Telerik team
answered on 26 Oct 2015, 09:53 AM
Hello Pritesh,

Could you elaborate what approach exactly you're using to localize the DisplayNames of the property definitions? Also, are you changing the culture of the application at runtime?

We don't have an example showing this precise scenario right now, but if I understand more about your setup I may be able to point you in the right direction.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pritesh
Top achievements
Rank 1
answered on 26 Oct 2015, 03:15 PM
  1. Hello Petya,

                Thank you for help.
                I am using “Localization Using Custom Localization Manager” approach to localize the DisplayNames of the propertyGrid.
    Step by step code written for custom localization are give following.

    1. Create a custom Localization manager as following

        public class CustomLocalizationManager : LocalizationManager
        {
            public override string GetStringOverride(string key)
            {
                switch (key)
                {
                    //----------------------
                    case "lblProjectManager":
                        {
                            var temp = Enums.FindResource(key);
                            return temp;
                        }---------------------
                }

                return base.GetStringOverride(key);
            }   
    }

    2. In user control constructor set custom localization manager as following

    public partial class DialogProjectAddView : UserControl
        {

            public DialogProjectAddView()
            {
                Telerik.Windows.Controls.LocalizationManager.Manager = new CustomLocalizationManager();
                InitializeComponent();

                // RadGridSamples.BeginInsert();
            }
        }

    3. In Property Definition set resource key as following
    <telerik:PropertyDefinition   telerik:LocalizationManager.ResourceKey="lblProjectManager"   OrderIndex="6" Binding="{Binding ExtAuthorisedSignatory,  ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" Description="Sets Authorised Signatory Name" />

    The culture of the application set in On Startup method of application at runtime.
    All the code running properly but display name show blank. Please help me to find reason for this error. If you need any more information you are free to contact.
    Thanks…………………..

Regards
Pritesh Patel

0
Petya
Telerik team
answered on 29 Oct 2015, 01:48 PM
Hello Pritesh,

In order to localize the DisplayName properties of property definitions, I'd suggest adopting data annotations. I'm attaching a sample application showing the approach. Please review it and let me know if it is helpful.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pritesh
Top achievements
Rank 1
answered on 30 Oct 2015, 05:42 AM

Hello Petya,

Thank you for help and support.

I can't use adopting data annotations in my project due to following to reason.
1. My project is create using MVVM so reference of resource file not exit in Model
2. My project use entity frame work created model class to  I can apply attributes to the members

Can we use other approach ?
Kind regards
Pritesh

0
Petya
Telerik team
answered on 04 Nov 2015, 09:40 AM
Hi Pritesh,

The only other thing I can think of is to subscribe to the AutoGeneratingPropertyDefinition event of RadPropertyGrid and change the DisplayName for each PropertyDefinition there through the event arguments.
private void PropertyGrid1_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
{
    if (e.PropertyDefinition.DisplayName == "FirstName")
    {
        e.PropertyDefinition.DisplayName = PropertyGridResources.FirstName;
    }
}

To comply with the MVVM paradigm, you can adopt EventToCommandBehaviour.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PropertyGrid
Asked by
Andy
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Andy
Top achievements
Rank 1
Pritesh
Top achievements
Rank 1
Petya
Telerik team
Share this question
or