Behaviors
- 3 minutes to read
Behavior describes a functional aspect of a control. For example, you can use the Clock Behavior to turn a Label Control or Digital Gauge into a clock.
#Attach Behavior to a Control
Drop the BehaviorManager component from the Visual Studio Toolbox onto a form. In the component’s smart tag menu, click Edit Behaviors.
In the invoked dialog, create a Behavior and assign it to a control.
In a control’s smart tag menu, you can also click Add Behaviors… to add the BehaviorManager component to the form and assign a Behavior to the control.
#Attach Behavior to a Control in Code
Use the BehaviorManager.Attach
method to associate a Behavior with a control in code. To remove the 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 the Behavior.
behaviorManager1.Detach<OpenFolderBehavior>(buttonEdit1);
The BehaviorManager.Attach
method returns an IDisposable object. You can also call its Dispose() method to remove the 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 the 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 |
---|---|---|
This Behavior adds a file/folder icon to a control if this control displays a path to an existing file or folder. | ||
Operates as the File | ||
These Behaviors add ellipsis buttons to a Button | ||
If you close and reopen a form with this Behavior, the form restores its last known position and size. |
Controls that implement the ISupport | |
Allows standard and DevExpress forms to snap to other windows and screen edges. | ||
Displays automatically generated icons for the target control or its child elements. | ||
Turns a control into a clock that displays the system’s date and time. | ||
Indicates whether system keys (Caps Lock, Num Lock, and Scroll Lock) are pressed. | ||
This Behavior allows a Picture | ||
Allows users to drag-and-drop items between controls. | ||
Allows users to invoke the Magnifier tool and pick colors on their screen. | All Color | |
With this Behavior, you can use a Radio | ||
Uses a Bread | ||
Allows you to disable row cells (in a grid and in treelist controls) and column cells (in a vertical grid) that meet a certain condition. |