[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
  [Collapse]Ribbon, Bars and Menu
      Add and Remove Toolbars
      Add Bar Items To Toolbars
      Bar Item Links
      Provide Functionality to Bar Items
      Toolbar Customization
      Recently Used Items
      Create Popup Menus
     MDI Merging
    [Expand]Bar Manager Designer
    [Expand]Runtime Customization and Layout Management
    [Expand]Appearance and Hotkeys
   [Expand]Popup Menus
    Radial Menu
   [Expand]Common Features
  [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
  [Expand]Form Layout Managers
  [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)

Provide Functionality to Bar Items

This document explains how to supply bar items with functionality.

Expanded Base Bar Item Events

All bar items provide the BarItem.ItemClick event that allows you to respond to end-users clicking this item. At design time, double-click a bar item link to automatically create a handler for this event and switch to this handler's code.

The item - item link concept allows you to re-use a bar item in multiple separate locations and grant individual appearances for each bar item link. It is presumed however that item functionality is shared across all links of the same bar item. Thus, links do not provide their own Click events and clicking a link always raises events of its parent item.

The BarItem.ItemClick event receives an argument of the ItemClickEventArgs type, which provides read-only ItemClickEventArgs.Item and ItemClickEventArgs.Link properties. Using these properties, you can identify the clicked link and its parent bar item.

Apart from the BarItem.ItemClick event, simple bar items also provide the BarItem.ItemPress and BarItem.ItemDoubleClick events.

Expanded Bar Edit Item Events

BarEditItem objects provide the BarEditItem.ShowingEditor, BarEditItem.ShownEditor and BarEditItem.HiddenEditor events, which raise when the editor within the target bar edit item is opened or closed. The BarEditItem.ShowingEditor event can be canceled, which allows you to prevent the editor from opening.

For other tasks, handle events provided by embedded editors themselves. For instance, the RepositoryItem.EditValueChanging and RepositoryItem.EditValueChanged events are core events shared among all editors. These events allow you to track the editor's BaseEdit.EditValue property, which reflects the current editor state (entered text for TextEdit editors, active tokens for TokenEdit editors, boolean values for CheckEdit editors, checked items for CheckedComboBoxEdit editors, etc.). The editor EditValueChanged event is also exposed to parent bar edit items, see the BarEditItem.EditValueChanged link to learn more.

Expanded Global Bar Manager Events

The BarManager component provides global events raised when any link that belongs to this manager is clicked, pressed, checked, double-clicked, etc. These are the BarManager.ItemClick, BarManager.ItemPress, BarManager.ItemDoubleClick, ComponentEditorContainer.EditorKeyPress and ComponentEditorContainer.EditorKeyUp events. Handle these events to perform actions common to multiple bar item links.

Expanded MVVM Command Binding

Most DevExpress controls and components provide the built-in support for the WinForms MVVM pattern. This includes multiple BindCommand and BindCommand[Type] method overloads, which allow you to associate a clickable UI element with the DelegateCommand object. For instance, BarButtonItem objects provide BarButtonItem.BindCommand and DevExpress.XtraBars.BarButtonItem.BindCommand``1 methods.

Delegate commands support the CanExecute condition. If the specific criteria is not met and the boolean CanExecute method returns false, a UI element bound to this command renders as disabled. For instance, end-users will be unable to press the "Edit Record" button if no Data Grid row is currently selected.

Refer to the Commands article to learn more.

Expanded See Also

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