[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Collapse]Form Layout Managers
    Side Panel
   [Collapse]Layout and Data Layout Controls
    [Expand]Product Information
    [Expand]Getting Started
    [Expand]Layout Control
    [Expand]Data Layout Control
    [Expand]Layout Items
    [Expand]Layout Groups
    [Expand]Tabbed Groups
    [Expand]Other Layout Elements
    [Expand]Design-Time and Runtime Customization
    [Expand]Size and Alignment
     Flow Layout
     Table Layout
     Focus Management
    [Expand]Appearance and Look and Feel
      How to: Access an item located at a specific point
      How to: Add new menu item to the Layout Tree View Context Menu
      How to: Create a layout in Regular mode in code
      How to: Create a layout in Table mode in code
      How to: Create a tabbed group in code
      How to: Create custom customization form
      How to: Create custom 'fixed' item
      How to: Create layout groups and items in code
      How to: Custom align a control within its layout item
      How to: Enable the Auto-Size Feature for a CheckEdit and Align It Horizontally
      How to: Implement custom functionality for layout context menu
      How to: Make a LayoutControl transparent
      How to: Print a LayoutControl and show its print preview
      How to: Provide accessible names for embedded controls
      How to: Provide Size Constraints for Control via IXtraResizable Interface
      How to: Save and restore layout
      How to: Save the layout between application runs
      How to: Specify which properties to display in the Property Grid when selecting layout items
      How to: Update a Layout Item and its Control
    [Expand]Member Tables
   [Expand]Tabbed MDI Manager
    Tab Control
   [Expand]Wizard Control
    Workspace Manager
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Create custom 'fixed' item

Specific layout items are constantly displayed in the Customization Form, and are never removed from the Customization Form when dragged onto a Layout Control. These items are called 'fixed'. They come first, and are painted bold in the Customization Form. Currently, the Layout Control supports the following predefined 'fixed' items: Empty Space Items, Label, Separator and Splitter.

The LayoutControl.RegisterFixedItemType method allows a custom 'fixed' item to be registered for runtime use in a Layout Control. This item will be constantly displayed in the Customization Control at runtime, and when an end-user drops it onto a Layout Control, your custom code will be called and an instance of it will be created.

First, create a custom 'fixed' item by deriving it from the LayoutControlItem class and implementing the DevExpress.XtraLayout.IFixedLayoutControlItem interface. Second, the item must be registered via the LayoutControl.RegisterFixedItemType method.

The following example shows how to create a custom 'fixed' item, named MyFixedLabelItem, representing a link displaying a URL. The item will contain a LinkLabel control. The following methods have been overridden and added:

  • The TypeName property must return the name of the "fixed" item's type. This property must always be overridden when creating custom layout items.
  • The MyFixedLabelItem constructor contains initialization code. This constructor is called when a layout item is registered within the Layout Control, the "fixed" item is dropped onto the control or when a layout is restored from a data store.
  • The Text property specifies the current link's text. This property is overridden to support layout serialization. This property's value is saved/restored when a layout is saved to/restored from a data store.
  • The new Link property specifies the current link's text. It's synchronized with the layout item's Text property. This property will be displayed in the Property Grid in the Customization Form. See below.

    When the Link property is changed, the new link is automatically assigned to the Text property of the embedded LinkLabel control (see the OnLinkChanged method).

  • The IFixedLayoutControlItem.OnCreateControl method. This method is called when an instance of the "fixed" layout item is about to be created (when the "fixed" item is dragged and dropped from the Customization Form onto the form or a layout is restored from a data store). Typically, this method must be overridden to create a control to be displayed in the layout item.
  • The IFixedLayoutControlItem.OnInitialize method. Typically, this method must be overridden to initialize the created item. This method is called after the OnCreateControl method.
  • The IFixedLayoutControlItem.OnDestroy method. In this method, destroy the control that has been previously created and release all allocated resources.
  • The IFixedLayoutControlItem.CustomizationName property must return the text representing the "fixed" item in the Customization Form.
  • The IFixedLayoutControlItem.CustomizationImage property must specify an image that will be displayed next to the text specified by the CustomizationName property.
  • The IFixedLayoutControlItem.AllowChangeTextLocation property must return a value that specifies whether a specific menu item is available via the Context Menu, that allows an end-user to change the item's text location.
  • The IFixedLayoutControlItem.AllowChangeTextVisibility property must return a value that specifies whether a specific menu item is available via the Context Menu, allowing an end-user to hide/show the item's text.
  • The IFixedLayoutControlItem.AllowClipText property must return a value that specifies whether the item's caption can be clipped, or it's always displayed in its entirety.

Properties of layout items are displayed in the Customization Form's Property Grid. The Layout Control allows only specific properties to be displayed for specific types of layout items. To do this, a BasePropertyGridObjectWrapper descendant must be created. Public properties that this class introduces will be displayed in the Property Grid. Other properties will not be available.

A custom BasePropertyGridObjectWrapper descendant must be associated with a specific layout item's type via the LayoutControl.RegisterCustomPropertyGridWrapper method. As a result, when selecting a layout item of this type, a corresponding BasePropertyGridObjectWrapper object will be used, that will specify which properties to display.

In the example, the MyFixedLabelPropertiesWrapper class is created and associated with the MyFixedLabelItem class. The MyFixedLabelPropertiesWrapper class contains only one public property - Link. When any layout item of the MyFixedLabelItem type is selected, the Property Grid will display only the Link property.

The following image shows the result:

Is this topic helpful?​​​​​​​