Extended Library for WPF and Silverlight | ComponentOne
In This Topic
    Displaying Methods and Properties
    In This Topic

    When the value of the SelectedObject property changes, the C1PropertyGrid updates itself based on the settings of three properties:

     

    Property

    Setting

    PropertyAttributes

    If this property is set to a non-empty collection, then the collection is used to generate the UI. Only the properties or methods included in the collection are displayed as long as the C1PropertyGrid.AutoGenerateProperties property is set to False. Otherwise all the properties will be shown and this collection will be used to override the default display of the properties or methods.

    AutoGenerateProperties

    If the PropertyAttributes collection is empty and this property is set to True (the default), then the C1PropertyGrid automatically shows all public properties of the SelectedObject.

    AutoGenerateMethods

    If the PropertyAttributes collection is empty and this property is set to True, then the C1PropertyGrid automatically shows all public methods of the SelectedObject that take no parameters. Methods are shown as buttons which can be clicked to invoke the method.

     

    For example, the following code would cause the C1PropertyGrid control to show one group with two entries in it for customer name and e-mail address:

    Visual Basic
    Copy Code
    ' Create C1PropertyGrid
    Dim pg = New C1PropertyGrid()
    LayoutRoot.Children.Add(pg)
    
    ' Customize the C1PropertyGrid layout
    pg.LabelWidth = 100
    
    ' Show customer properties
    pg.SelectedObject = customer
    
    ' Customize what is shown to the user
    pg.AutoGenerateProperties = False
    pg.PropertyAttributes.Add(New PropertyAttribute())
    pg.PropertyAttributes.Add(New PropertyAttribute())
    

    C#
    Copy Code
    // Create C1PropertyGrid
    var pg = new C1PropertyGrid();
    LayoutRoot.Children.Add(pg);
    
    // Customize the C1PropertyGrid layout
    pg.LabelWidth = 100;
    
    // Show customer properties
    pg.SelectedObject = customer;
    
    // Customize what is shown to the user
    pg.AutoGenerateProperties = false;
    pg.PropertyAttributes.Add(new PropertyAttribute()
      {
        MemberName = "Name",
        DisplayName = "Customer Name",
        Category = "Contact"
      }
    );
    pg.PropertyAttributes.Add(new PropertyAttribute()
      {
        MemberName = "EMail",
        DisplayName = "e-Mail Address",
        Category = "Contact"
      }
    );
    

     

    You can use this method to customize the display of objects that you have no access to. For example, if your Customer class were defined in a third-party assembly, you would not be able to add attributes to its members but would still be able to customize how the object is shown in the C1PropertyGrid.

    Note that the MemberName must match the exact name of a property or method; otherwise the entry will be ignored.