windowsforms-devexpress-dot-xtrabars-dot-ribbon-dot-ribboncontrol-39452539.md
Allows you to customize the Ribbon menu or prevent it from being displayed based on a condition.
Namespace : DevExpress.XtraBars.Ribbon
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event ExpandCollapseMenuShowingEventHandler ExpandCollapseMenuShowing
<DXCategory("Events")>
Public Event ExpandCollapseMenuShowing As ExpandCollapseMenuShowingEventHandler
The ExpandCollapseMenuShowing event's data class is ExpandCollapseMenuShowingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Allow | Gets or sets whether to display a popup menu. |
| Menu | Gets a popup menu. |
If the OptionsExpandCollapseMenu.EnableExpandCollapseMenu option is enabled, the Ribbon control displays a popup menu with display options after a user has clicked the Ribbon Display Options button.
The Ribbon control raises the ExpandCollapseMenuShowing event before the menu is displayed. Handle this event to customize the menu or prevent it from being displayed.
Use the e.Menu property to obtain the popup menu.
Set the e.Allow property to DefaultBoolean.False to prevent the menu from being displayed.
using DevExpress.Utils;
using DevExpress.XtraBars.Ribbon;
private void Form1_Load(object sender, EventArgs e) {
EnableRibbonExpandCollapseMenu();
}
void EnableRibbonExpandCollapseMenu() {
ribbonControl1.OptionsExpandCollapseMenu.EnableExpandCollapseMenu = DefaultBoolean.True;
ribbonControl1.OptionsExpandCollapseMenu.ShowRibbonLayoutGroup = DefaultBoolean.True;
ribbonControl1.ExpandCollapseMenuShowing += RibbonControl1_ExpandCollapseMenuShowing;
}
private void RibbonControl1_ExpandCollapseMenuShowing(object sender, ExpandCollapseMenuShowingEventArgs e) {
// Use 'e.Menu' to add new menu items aor customize the existing menu items.
// e.Menu.AddItem(barItem);
// e.Menu.ItemLinks[0].Caption = "CUSTOM_CAPTION";
// Prevents the menu from being displayed.
// e.Allow = false;
}
Imports DevExpress.Utils
Imports DevExpress.XtraBars.Ribbon
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
EnableRibbonExpandCollapseMenu()
End Sub
Private Sub EnableRibbonExpandCollapseMenu()
ribbonControl1.OptionsExpandCollapseMenu.EnableExpandCollapseMenu = DefaultBoolean.True
ribbonControl1.OptionsExpandCollapseMenu.ShowRibbonLayoutGroup = DefaultBoolean.True
AddHandler ribbonControl1.ExpandCollapseMenuShowing, AddressOf RibbonControl1_ExpandCollapseMenuShowing
End Sub
Private Sub RibbonControl1_ExpandCollapseMenuShowing(ByVal sender As Object, ByVal e As ExpandCollapseMenuShowingEventArgs)
' Use e.Menu to add new menu items aor customize the existing menu items.
' e.Menu.AddItem(barItem);
' e.Menu.ItemLinks[0].Caption = "CUSTOM_CAPTION";
' Prevents the menu from being displayed.
' e.Allow = false;
End Sub
The following screenshot shows the result:
See Also