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

Display a different custom set of PropertyDefinitions based on object type?

6 Answers 206 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 22 Aug 2013, 04:50 PM
I'm trying to implement a property editor control for an application using the RadPropertyGrid. The user will select from a list of objects and the propertygrid editor needs to change based on the object type. That would be perfectly fine if we were giving access to ALL properties of each object, but we only want to display specific subset of each object to the end user, and that subset will vary based on each object type. For example, an object of type Circle we may want to display the center point coordinates and a radius, while a Rectangle we want to display lower-left coordinates and a width and height. These object classes are defined in a 3rd party library, and each of them have many other properties we don't want to expose.

Ideally it would be great if we could set AutoGeneratePropertyDefinitions to false and define a different set of RadPropertyGrid.PropertyDefinitions for each type, then switch that set of definitions based on the object type. I've used converters to change controls' style properties based on object types before, but since since the PropertyDefinitions isn't a property itself, I can't use that same technique.

Any suggestions?

Thanks!

6 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 27 Aug 2013, 03:22 PM
Hello,

Basically, the best approach would be to use the Browsable attribute. Setting it to false, would make RadPropertyGrid skip the respective property. However, I am not sure whether you can easily do this, as you have mentioned some third party assembly. The other, in my opinion acceptable, approach is to maintain some data structure (i.e. a Dictionary) with the list of properties that should be displayed for a certain type. Then, in the AutoGeneratingPropertyDefinition handler the PropertyDefinitions, which DisplayName does not match any one listed in the data structure, gets canceled, by setting args.Cancel = true.

Regards,
Ivan Ivanov
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
Robert
Top achievements
Rank 1
answered on 30 Aug 2013, 04:07 PM
Thanks for your help! I ended up doing a variation of what you suggested. Basically I created a new class is a list of property names but also has a property that defines an object type that it should be tied to. Then I extended the RadPropertyGrid class to have a new property that accepted a list of instances of this new class. Since the RadPropertyGrid doesn't have an event that fires when its Item property changes (or, if its an INotifyCollectionChange item, an event when the collection changes), I overrode the Item property with my dependency property which fires a change event.  That change event can then handle choosing the appropriate property list(s) for the object(s) being bound to the PropertyGrid.

Finally I subscribed to the AutoGeneratingPropertyDefinition and in the handler checked to see if the property being generated was in the property list, and if it wasn't cancelled the events.

With this technique I'm able to create xaml definitions for each object type I have and the list of properties that should be displayed for each one, and bind them to the extended RadPropertyGrid control and filter the object's properties that way.

Thanks again for your help!
0
De
Top achievements
Rank 1
answered on 02 May 2014, 08:22 PM
Another option is to make the DataTemplateSelector more intelligent (through EditorTemplateSelector).  Since the DataTemplateSelector knows when 'item' changes as well as it can own a list of DataTemplates (you have to inject in), the DataTemplateSelector can check the type of item (as DataContext) and selects the appropriate DataTemplate.  
0
Mahdi
Top achievements
Rank 1
answered on 12 May 2014, 02:12 PM
Hello,

I have RadPropertyGrid and want to bind Item Property to variable of type "object". When I run program, objects with different properties created and their properties must be shown in PropertyGrid. But always property of first created object displayed and didn't changed for other objects.
Is there any sample that show Robert solution for overriding RadPropertyGrid or any property that I could set in RadPropertyGrid and solve this problem.

Sincerely,
0
Ivan Ivanov
Telerik team
answered on 15 May 2014, 12:53 PM
Hello,

Well, it seems that your scenario is different from the original one, as you are not aiming to display only a limited set of properties, am I right? Basically, RadPropertyGrid automatically rebinds its data engine as soon as the Item property gets its value changed. Do you raise the PropertyChanged event after the bound property gets updated? In case this is not cause, can you please send us a sample dummy project that we can debug on our side?

Regards,
Ivan Ivanov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Mahdi
Top achievements
Rank 1
answered on 28 May 2014, 03:04 PM
your right, Ivan Ivanov.

I use PostSharp for adding PropertyChanged to my class properties. But after many inspecting in my code, I realized that because of some mistake in my Multicasting, this event not added to my code and cause error like that.

Thank you for your advice.
Tags
PropertyGrid
Asked by
Robert
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Robert
Top achievements
Rank 1
De
Top achievements
Rank 1
Mahdi
Top achievements
Rank 1
Share this question
or