Skip to main content
A newer version of this page is available. .

LayoutControl.RegisterCustomPropertyGridWrapper(Type, Type) Method

Registers the specified wrapper object that identifies which properties to display for specific layout items in the Customization Form‘s Property Grid.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v19.1.dll

Declaration

public void RegisterCustomPropertyGridWrapper(
    Type itemType,
    Type customWrapperType
)

Parameters

Name Type Description
itemType Type

The type of layout item with which the current wrapper object is associated.

customWrapperType Type

The type of the wrapper object to be registered.

Remarks

Selecting a layout item at runtime in customization mode displays the item’s properties in the Customization Form’s Property Grid. It’s possible to control which properties must be displayed in the Property Grid when selecting items of particular types. To do this:

  1. Create a DevExpress.XtraLayout.BasePropertyGridObjectWrapper class descendant.
  2. Add required public properties to this class, that will refer to corresponding properties of a layout item. Only the public properties declared will be displayed in the Property Grid. When implementing the class’ properties, to access the current layout item object, use the inherited WrappedObject property.
  3. Associate the created wrapper object with a specific type of layout item via the RegisterCustomPropertyGridWrapper method. As a result, when selecting any layout item of this type, the Property Grid will display only the properties defined by the corresponding wrapper object.

See example below. Another example can be found in How to: Create custom ‘fixed’ item.

Example

The following example shows how to display only specific properties in the Customization Form’s Property Grid, when selecting regular layout items (items of the LayoutControlItem type), and sort these properties in alphabetical order.

To control which properties to display in the Property Grid when selecting layout items, a BasePropertyGridObjectWrapper class descendant is created. In the example, the MyLayoutControlItemPropertyWrapper class is created, introducesingthree public properties: Text, TextLocation and TextVisible. This class is associated with layout items of the LayoutControlItem type via the LayoutControl.RegisterCustomPropertyGridWrapper method. As a result, when selecting any LayoutControlItem object at runtime in customization mode, the Property Grid will display only the public properties specified by the MyLayoutControlItemPropertyWrapper class.

Note

When creating a Wrapper object, the Clone method must be overridden. It must return a copy of the current object.

To display properties in the Property Grid in alphabetical order, the LayoutControl.ShowCustomization event is handled. In this event handler, the Property Grid control is accessed and its PropertySort property is set to PropertySort.Alphabetical.

CustomPropertyGridWrapper

using DevExpress.XtraLayout;
using DevExpress.XtraLayout.Customization;

public class MyLayoutControlItemPropertyWrapper : BasePropertyGridObjectWrapper {
    protected LayoutControlItem Item { 
        get { return WrappedObject as LayoutControlItem; } 
    }
    [DescriptionAttribute("Gets or sets the item's text")]
    public string Text { 
        get { return Item.Text; } 
        set { Item.Text = value; } 
    }
    [DescriptionAttribute("Gets or sets the position of the text region")]
    public DevExpress.Utils.Locations TextLocation { 
        get { return Item.TextLocation; } 
        set { Item.TextLocation = value; } 
    }
    [DescriptionAttribute("Gets or sets whether the text region is visible")]
    public bool TextVisible { 
        get { return Item.TextVisible; } 
        set { Item.TextVisible = value; } 
    }

    public override BasePropertyGridObjectWrapper Clone() {
        return new MyLayoutControlItemPropertyWrapper();
    }
}

private void Form1_Load(object sender, EventArgs e) {
    // Associate the wrapper object with LayoutControlItem objects.
    layoutControl1.RegisterCustomPropertyGridWrapper(typeof(LayoutControlItem), 
        typeof(MyLayoutControlItemPropertyWrapper));
}

// Show properties in the Property Grid in alphabetical order.
private void layoutControl1_ShowCustomization(object sender, EventArgs e) {
    LayoutControl lc = sender as LayoutControl;    
    CustomizationForm form = lc.CustomizationForm as CustomizationForm;
    // Customize the Property Grid's sort settings.
    (form.propertyGridItem.Control as PropertyGrid).PropertySort = PropertySort.Alphabetical;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the RegisterCustomPropertyGridWrapper(Type, Type) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also