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

NestedProperties and ICustomTypeDescriptor

5 Answers 319 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 13 Jan 2013, 04:20 PM

Hi,

I'm trying to use NestedProperties feature with CustomTypeDescriptor and custom PropertyDescriptor, but the autogenerated PropertyDefinition does not have NestedProperties and HasNestedProperties is false:

void AutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
    {
       
      var descriptor = e.PropertyDefinition.SourceProperty.Descriptor as PropertyDescriptor;
      if (descriptor != null)
      {
          //e.PropertyDefinition.NestedProperties.Count == 0
          //but descriptor.GetChildProperties().Count > 0
             //why?
       }
    }

in my scenario:

  • I set AutoGenerateProperties = true and NestedPropertiesVisibility = true;
  • I have class MyCustomObject which implements ICustomTypeDescriptor (namespace System.ComponentModel)
  • I have class CustomPropertyDesctriptor that inherits from PropertyDescriptor (namespace System.ComponentModel)
  • ICustomTypeDescriptor.GetProperties implementation on MyCustomObject returns a collection of CustomPropertyDescriptor.
    Sometimes CustomPropertyDescriptor.GetValue(object component) returns new MyCustomObject instance so I have tree hierarchy

What's the condtition I need to satisfy to autogenerate NestedProperties' PropertyDefinitions?

it is not so easy to create sample project to simulate my scenario but I can do that if you can't answer without it

5 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 15 Jan 2013, 05:09 PM
My suggestion is to add property to PropertyDefition, which would force NestedProperties for current property. Then it would be easy to control nested propeties by DataAnnotation, for example:

public class PropertyDefinition
{
...
  public bool? ShouldExpandNestedProperties { get; set; }
}
 
//in codebehind
void AutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
{
  var descriptor = e.PropertyDefinition.SourceProperty.Descriptor as PropertyDescriptor;
  if (descriptor != null)
  {
    NestedPropertiesAttribute nestedProperties = descriptor.Attributes.OfType<NestedPropertiesAttribute>().FirstOrDefault();
    if (nestedProperties != null)
    {
       e.PropertyDefitionion.ShouldExpandNestedProperties = nestedProperties.ShouldExpand;
    }
  }
}





I looked at the RadPropertyGrid's sourcecode using justdecompile. There is an internal method PropertyDefinition.ShouldExpandNestedProperties or something simmilar (i dont remember exactly).
There is an special contidion for ICustomTypeDescriptor which probably causes problems.
My solution would be elegant workaround.
0
Alan
Top achievements
Rank 1
answered on 07 Feb 2013, 08:55 AM
I also vote for giving us a hook like this via annotations or in the auto-generate callback.
Some way during the auto-generate to tell it to recursively decent for the nested properties would be helpful.
Doing this all in XAML isn't very dynamic like some of us need.
0
Ivan Ivanov
Telerik team
answered on 12 Feb 2013, 09:24 AM
Hi guys,

Our initial idea to deal with such scenarios was to check whether all of the nested properties are browsable or not. However, this will hardly work well when dynamic properties are used. We will consider introducing a more general alternative. It will possibly be available at some moment between the release of Q1 2013 (the last week of Feb) and the SP.

All the best,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Alex
Top achievements
Rank 1
answered on 02 Sep 2016, 11:10 AM
I have the similar problem now. Is this issue already solved somehow?
0
Stefan
Telerik team
answered on 05 Sep 2016, 12:32 PM
Hello Alex,

In order to ensure that we are on the same page, can you please demonstrate the exact issue you are experiencing in a new support thread? Also, providing a demo application that mimics your project setup would be quite useful. You can take a look a this blog post for further reference.

Thanks in advance for your cooperation.

Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PropertyGrid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Alan
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Alex
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or