Changing DisplayName Language on the fly

10 posts, 1 answers
  1. Andy
    Andy avatar
    10 posts
    Member since:
    Aug 2013

    Posted 03 Sep 2013 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Sep 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Andy
    Andy avatar
    10 posts
    Member since:
    Aug 2013

    Posted 04 Sep 2013 Link to this post

    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
  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 04 Sep 2013 Link to this post

    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 >>
  6. Pritesh
    Pritesh avatar
    4 posts
    Member since:
    Feb 2014

    Posted 21 Oct 2015 Link to this post

    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

  7. Petya
    Admin
    Petya avatar
    975 posts

    Posted 26 Oct 2015 Link to this post

    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
  8. Pritesh
    Pritesh avatar
    4 posts
    Member since:
    Feb 2014

    Posted 26 Oct 2015 Link to this post

    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

  9. Petya
    Admin
    Petya avatar
    975 posts

    Posted 29 Oct 2015 Link to this post

    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
  10. Pritesh
    Pritesh avatar
    4 posts
    Member since:
    Feb 2014

    Posted 30 Oct 2015 Link to this post

    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

  11. Petya
    Admin
    Petya avatar
    975 posts

    Posted 04 Nov 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready