NestedProperties and ICustomTypeDescriptor

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    23 posts
    Member since:
    May 2009

    Posted 13 Jan 2013 Link to this post

    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

  2. Daniel
    Daniel avatar
    23 posts
    Member since:
    May 2009

    Posted 15 Jan 2013 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alan
    Alan avatar
    25 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    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.
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 12 Feb 2013 Link to this post

    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.

  6. Alex
    Alex avatar
    1 posts
    Member since:
    Aug 2016

    Posted 02 Sep Link to this post

    I have the similar problem now. Is this issue already solved somehow?
  7. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 05 Sep Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready