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 Currently I am evaluating the WPF Property Grid with a view to use it with one of our WPF applications. We need to be able to localise the display name of the properties displayed in the property grid. Is there any functionality that supports this? If not, is it achievable? and are there any examples that I can refer to.Many thanksJav Ainesaz
|
|
|
No, there is no built-in support for localising display names. You can control the display name using the DisplayNameAttribute, which will suffice for localising into one language known at compile time, but I am guessing that you need to be able to display names in different languages depending on the runtime setting. If that's the case, there are a couple of ways of tackling this: 1. Implement ICustomTypeDescriptor on the bound object. The only member with a non-trivial implementation would be GetProperties. (Everything else would just delegate to the corresponding TypeDescriptor.GetXxx method.) GetProperties would call Type.GetProperties (or TypeDescriptor.GetProperties with the noCustomTypeDescriptor flag), but would then get the localised display name from somewhere (e.g. a resource file) and add a DisplayNameAttribute with the returned display name to the PropertyDescriptor. The advantages of this method are that it doesn't require any customisation of the grid, and that it will work with anything else that uses the ComponentModel descriptor system to display/browse properties; the disadvantage is that it requires changes to the bound object class. 2. Create a custom data template for displaying the name, and assign it to the grid using the PropertyNameTemplate property. Your data template receives a PropertyGridRow, from which you can access the Node.Property. Now you can use an IValueConverter to get a localised display name out of there, again depending on how you plan to store and look up your localised names. For example, imagining that you are using a custom DisplayNameKeyAttribute on the property to specify a lookup key which is then used to locate the localised name in a resource file: public class LocalisedDisplayNameConverter : IValueConverter Note that if you go this route you need to create the whole left hand side template, including the expander. A basic version looks something like this: <local:LocalisedDisplayNameConverter x:Key="LocalisedDisplayName" /> The advantage of this approach is that it requires no changes to the bound object class. Note that for either of these approaches you will need to be using the nightly build, available from http://www.mindscape.co.nz/products/wpfpropertygrid/nightlybuilds.aspx. |
|