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

Property definitions for a single property grid used with multiple classes

1 Answer 121 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 14 Feb 2013, 12:02 PM
Hi
I am trying to use a single propertygrid that will be bound to an object that changes its type depending on user input.

This works fine when AutoGeneratePropertyDefinitions="true". However, I want to define my own property definitions depending on the type.

How do you recommend I do this?

Thanks
Craig

1 Answer, 1 is accepted

Sort by
0
Radiation
Top achievements
Rank 1
answered on 15 Feb 2013, 12:46 PM
I would recommend you either implement ICustomTypeDescriptor together with autogenerating property  (1) , or use attached property behaviour (2).

(1) ICustomTypeDescriptor approach:
<telerik:RadPropertyGrid x:Name="propertyGrid1"
    AutoGeneratePropertyDefinitions="True"
    Item="{Binding SelectedObject, Converter={StaticResource CustomTypeDescriptorValueConverter}"
    />

CustomTypeDescriptorValueConverter would convert your object to an instance of class that implements ICustomTypeDescriptor.
ICustomTypeDescriptor returns list of properties and attributes at runtime

(2) attached property approach
<telerik:RadPropertyGrid x:Name="propertyGrid1"
    AutoGeneratePropertyDefinitions="False"
    local:CustomPropertyDefinitionsGenerator.Item="{Binding SelectedObject}"
    />

so you define your own attached property "Item". In the property's PropertyChangedCallback you have reference to the RadPropertyGrid as well as the object you want to edit. You can create propertydefinitions here and inject them into RadPropertyGrid.PropertyDefinitions


Tags
PropertyGrid
Asked by
Craig
Top achievements
Rank 1
Answers by
Radiation
Top achievements
Rank 1
Share this question
or