Behaviors

  • 3 minutes to read

Behavior describes a functional aspect of a control. For example, you can use the Clock Behavior to turn a LabelControl or a digital gauge into a clock.

Behaviors - Clock Behavior

Attach Behavior to a Control

Drop the BehaviorManager component from Visual Studio’s Toolbox onto a form. In the component’s smart tag, click Edit Behaviors.

Behaviors - Component Smarttag

Use the opened dialog to create Behavior and assign it to a control.

Behaviors - Collection Editor

In a control’s smart tag menu, you can also click Add Behaviors… to add the BehaviorManager component to the form and assign Behavior to the control.

Behaviors - Attach Behavior

Attach Behavior to a Control in Code

Use the BehaviorManager.Attach method to associate Behavior with a control in code. To remove Behavior, use the BehaviorManager.Detach method.

using DevExpress.Utils.Behaviors.Common;

behaviorManager1.Attach<OpenFolderBehavior>(buttonEdit1, behavior => {
    behavior.Properties.IconSize = FileIconSize.Small;
    behavior.Properties.InvalidPathImage = DevExpress.Images.ImageResourceCache.Default.GetImage("images/actions/close_16x16.png");
    behavior.Properties.ShowIcon = true;
});

//Use the Detach method to remove Behavior.
behaviorManager1.Detach<OpenFolderBehavior>(buttonEdit1);

The BehaviorManager.Attach method returns an IDisposable object. You can also call its Dispose() method to remove Behavior.

using DevExpress.Utils.Behaviors.Common;

var openFolderBehavior1 = behaviorManager1.Attach<OpenFolderBehavior>(buttonEdit1, behavior => {
    behavior.Properties.IconSize = FileIconSize.Small;
    behavior.Properties.InvalidPathImage = DevExpress.Images.ImageResourceCache.Default.GetImage("images/actions/close_16x16.png");
    behavior.Properties.ShowIcon = true;
});

//Use the Dispose method to remove Behavior.
openFolderBehavior1.Dispose();

If the BehaviorManager is no longer needed, you can call its Dispose() method to remove all Behaviors associated with the Manager.

Available Behaviors

The table below lists available Behaviors and controls that support them.

Behavior

Description

Target Controls

FileIconBehavior

This Behavior adds a file/folder icon to a control if this control displays a path to an existing file or folder.

TextEdit

ButtonEdit

LabelControl

FilePathBehavior

Operates as the FileIconBehavior and can show auto-complete hints.

TextEdit

ButtonEdit

OpenFileBehavior

OpenFolderBehavior

These Behaviors add ellipsis buttons to a ButtonEdit. Users can click these buttons to invoke file/folder browser dialogs. The editor displays the selected file/folder’s icon and caption.

ButtonEdit

PersistenceBehavior

If you close and reopen a form with this Behavior, the form restores its last known position and size.

XtraForm

Ribbon Form

Tabbed Form

Controls that implement the ISupportXtraSerializer interface

SnapWindowBehavior

Allows standard and DevExpress forms to snap to other windows and screen edges.

XtraForm

Ribbon Form

Tabbed Form

Form

StubGlyphBehavior

Displays automatically generated icons for the target control or its child elements.

GridColumn

ImageComboBoxEdit

LayoutControlGroup

LayoutControlItem

XtraTabPage

TreeListColumn

ImageListBoxControl

ClockBehavior

Turns a control into a clock that displays the system’s date and time.

LabelControl

BarStaticItem

DigitalGauge

KeyboardIndicatorBehavior

Indicates whether system keys (Caps Lock, Num Lock, and Scroll Lock) are pressed.

LabelControl

BarStaticItem

BannerBehavior

This Behavior allows a PictureEdit to automatically cycle through a collection of images.

PictureEdit

DragAndDropBehavior

Allows users to drag-and-drop items between controls.

ListBoxControl

GridView

TileView

TreeList

Magnifier Behavior

Allows users to invoke the Magnifier tool and pick colors on their screen.

All ColorEdit descendants

Pager Navigation Behavior

With this Behavior, you can use a RadioGroup or WindowsUIButtonPanel to browse the target control’s child items (tiles, slide images, and so on).

TileControl

TileBar

NavigationFrame

ImageSlider

Breadcrumb Behavior

Uses a BreadCrumbEdit to implement navigation through a TreeList‘s hierarchy.

TreeList

BreadCrumbEdit