BaseLayoutItem.Accept(BaseVisitor) Method

Invokes the Visit method of the specified visitor for each layout item that belongs to the current layout item.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v20.1.dll

Declaration

public override void Accept(
    BaseVisitor visitor
)
Public Overrides Sub Accept(
    visitor As BaseVisitor
)

Parameters

Name Type Description
visitor DevExpress.XtraLayout.Utils.BaseVisitor

A DevExpress.XtraLayout.Utils.BaseVisitor class descendant.

Remarks

Specific layout items can own other layout items (for instance, the LayoutControlGroup and TabbedControlGroup classes). The Accept method provides recursive iteration through the layout items that belong to the current layout item and enables specific operations to be performed on each item.

To iterate through the items do the following:

  • Create a DevExpress.XtraLayout.Utils.BaseVisitor class descendant;
  • Override its Visit method to implement an operation to be performed on layout items;
  • Call the layout item's Accept method with an instance of the created class as a parameter. The Visit method will be invoked for the current layout item first and then for each child item.

As implemented in the BaseLayoutItem class the Accept method simply invokes the Visit method of the specified visitor and passes the current object to this method. The Accept method is overridden in the LayoutControlGroup and TabbedControlGroup classes to allow child layout items to be traversed.

Examples

The following code shows how to iterate through the items that belong to a specific layout item group. To iterate through the items the LayoutGroup.Accept method is used.

This method takes a descendant of the DevExpress.XtraLayout.Utils.BaseVisitor class as a parameter. When this method is called it iterates through the items that belong to the current layout item group and invokes the visitor's Visit method for each layout item.

In the example, the Visit method of the MyVisitor class sets the BaseLayoutItem.TextVisible property to true for layout items.

// A custom visitor class.
class MyVisitor : DevExpress.XtraLayout.Utils.BaseVisitor {
   // This method will be invoked for each layout item in a group.
   public override void Visit(DevExpress.XtraLayout.BaseLayoutItem item) {
      if(item is DevExpress.XtraLayout.LayoutControlItem) {
         item.TextVisible = true;
      }
   }
}

// Get a layout group whose items should be iterated through.
DevExpress.XtraLayout.LayoutControlGroup group = layoutControl1.Root;
// Iterate through the items.
group.Accept(new MyVisitor());
See Also