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.v20.1.dll

Declaration

public void RegisterCustomPropertyGridWrapper(
    Type itemType,
    Type customWrapperType
)
Public Sub RegisterCustomPropertyGridWrapper(
    itemType As Type,
    customWrapperType As Type
)

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.

Examples

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;
}
See Also