PropertyGridLabel - Edit at runtime

Jan 20, 2011 at 1:30 PM

Is There any possible to set the Name of the Label in propertyGrid at runtime!?
I have an application multilanguage and i'm not able to change the "label name" from Italian to English ... 
Have you any way to do this!?
Thanks in advance!
Johnny

Coordinator
Jan 21, 2011 at 12:52 PM

You can edit this method on the proprty grid class to set your language.

static PropertyGridLabel CreateLabel(string name, string displayName)
		{
			TextBlock txt = new TextBlock()
			{
				-->Text = displayName, <--
				Margin = new Thickness(0)
			};
			return new PropertyGridLabel()
			{
				Name = Guid.NewGuid().ToString("N"),
				Content = txt
			};
		}

Jan 26, 2011 at 11:33 AM

Thanks a lot ... but at this moment I can't try this fix, and I don't know if it works or not.

Write U soon!

Johnny

 

 

Mar 2, 2011 at 10:00 AM

Hi,
I have the same problem.
I do not quite understand how to use the code above.

To set displayName,

After assign the SelectedObject of the property grid (this.propertyGrid.SelectedObject = person;)

I need to do a method to set display description of property on my language, for example:

this.propertyGrid.SetDisplayName( propertyName, newDisplayName )

is correct this?
can someone help me to make this method?

thank you

Coordinator
Mar 2, 2011 at 12:07 PM

This method alredy exists in the PropertyGrid class. So if you wanted to modify the Language for the display name, this is where you could do so. The project in and of itself does not directly support multilanguage. But since there is little to change in the regards it's easier for you to just mofify this method to allow for you language support needs.

Let me know if this helps...

Mar 2, 2011 at 4:13 PM

Hi,
thanks for fast reply.

What is the method? you can show me an example please?

Another information please... I took the dll generate from SL40PropertyGrid project and I included it in my project. This is good or should I include all the sources c# files?

Thank you very much.

Coordinator
Mar 3, 2011 at 2:03 PM

Localization is a little tricky and why I haven't done it as of yet. But, here goes a work around for specific cases...

For reference: http://msdn.microsoft.com/en-us/library/cc838238(v=VS.95).aspx#localization_and_resource_files

1. you need to create your resource file containing the key/value pairs asa the article above describes

2. Set your Culture and UICulture in App.cs
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr");

3. In the CreateLabel method use the Resrouce Manager to get the string to display
ResourceManager rm = null;
rm = new ResourceManager("SilverlightApplication1.Strings", Assembly.GetExecutingAssembly());
string displayValue = rm.GetString("DisplayValue");

It was a minor pain to set up, but after 20 minutes of messing around I was able to support French and English for a single resource item

Strings.resx
DisplayValue = Hello my name is Pierre

Strings.fr.resx
DisplayValue = Bonjour mon nom est Pierre

And yes, just reference the DLL is the easiest, unless you want to edit the source code then you would either need to recompile or add to your project source.