This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I am using Mindscape Property Grid 2.0 for propertygrid control in my project.This project will support 8 languages so the User interface will be shown as language selected. Currently I have written a class that having properties which is to be shown in the propertygrid. public class Parameter : Observable{ private String _Name; private Int16 _Id; public String Name { get{ return _Name;} set{ Set(ref _Name, value, "Name");} } public Int16 Id { get{ return _Id;} set{ Set(ref _Id, value, "Id");} } } and then bind this class object to propertygrid. PropertyGrid.SelectedObject = new Parameter();after this, property Grid display two properties with the name of "Name" and "Id" (same name as i gave to properties name of Parameter class ). Is it possible to change the display name for the properties Name and Id in parameter class? As i want to support so many languages,I need to change the display name of same properties (Name and Id) according to selected language. for the other controls like TextBox and Button we are using ResourceString. we are having Resource file(.resx) for each language.We get the string from resource file ResourceManager.GetString("btnTextString"); Please advice how to localize PropertyGrid control?
|
|
|
The normal way to override the display of property names is to apply the DisplayNameAttribute. However this will not work in your scenario because DisplayNameAttribute specifies only a single string, whereas you need to display different strings depending on the user's language. One possible approach to this is to implement ICustomTypeDescriptor, and make the names depend on the selected language. This is quite invasive to your object model though. The approach I would suggest therefore is to set the PropertyGrid.PropertyNameTemplate to a custom DataTemplate of your own. This DataTemplate would bind to Node, but use an IValueConverter to convert the node to a display name using whatever approach you wanted -- for example the value converter could look for a custom DisplayNameResourceIdAttribute, and then look that up in the resource file. Please note that if you replace the default PropertyNameTemplate it is up to you to supply *all* elements of the left hand column -- specifically you will need to provide the expander toggle button (the +/- button) and handle indentation. Examples of this can be found under Source / Styles in the installation directory, and you can use TreeListView.ExpandCollapseToggleStyleKey to reference the standard expander button style. |
|
|
Is there any reason you couldn't just derive from DisplayNameAttribute and override the DisplayName property? Your new attribute can do whatever localized lookup you want in the constructor. Seems to work pretty well, but maybe I'm missing something. |
|
|
Nice idea -- I hadn't noticed that DisplayNameAttribute was unsealed. Yes, that should work really well -- thanks! |
|
|
Works well for categories, too. There's one last piece I can't figure out -- how can I localize the 'Search' string in the property grid? Maybe expose a dependency property for this string which defaults to 'Search'?
|
|
|
We haven't previously provided a way to do this short of retemplating, but I've added a solution similar to the "Today" button localisation fix and this will be included in nightly builds dated 2 September 2009 and above. What you'll need to do is create a resource with the key ViewCommandsToolBar.SearchLabelContentKey. This should be in a local resource dictionary to the grid (basically anywhere that WPF consults before it falls back on the default grid resources). E.g. <Window xmlns:s="clr-namespace:System;assembly=mscorlib"> I realise this isn't quite as flexible as a DP but I don't want to clutter up the grid API with lots of properties to manage the UI down to this level, and I think the "magic resource key" will suffice for most localisation scenarios -- let us know if you really do need something stronger. |
|
|
You're right, that seems a bit cleaner. I'm assuming that you could then bind this string to a static variable in your ViewModel (which is pulled from a localized resource during its static initialization). That should work great. Thanks, Ivan! |
|