Property definitions for a single property grid used with multiple classes

2 posts, 0 answers
  1. Craig
    Craig avatar
    113 posts
    Member since:
    Nov 2011

    Posted 14 Feb 2013 Link to this post

    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?

  2. Radiation
    Radiation avatar
    13 posts
    Member since:
    Jul 2012

    Posted 15 Feb 2013 Link to this post

    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"
        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"
        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

Back to Top