Pop-Up Menus
- 5 minutes to read
The SchedulerControl is provided with four context menu types that enable an end-user to manage appointments, switch views and dates, adjust time ruler settings, edit groups and resources in the Resource Tree. You can customize any type of a context menu by adding or removing items, or replace the default menu with a custom one.
The built-in context menu item names are contained in the static DefaultBarItemNames class. Commands that these items execute are available from the SchedulerCommands and ResourceTreeCommands classes. Their instqances are used in the SchedulerControl.Commands and ResourceTreeControl.Commands properties respectively.
The list below describes available menu types with their items, related SchedulerCommands and ResourceTreeCommands, the DefaultBarItemNames properties used to access the menu items and API used to customize these menus.
Note
See the How to: Display and Modify the Integrated Ribbon for the Scheduler -> Customize the Ribbon UI for more information on how to use the default bar item names to modify the ribbon.
Pop-Up Menu Types
Cell Pop-Up Menu
Appears when right-clicking an empty time cell.
Appointment Pop-Up Menu
Appears when right-clicking an appointment.
Appointment Drag Pop-Up Menu
Appears when dragging an appointment with the right mouse button.
Time Ruler Pop-Up Menu
Appears when right-clicking a time ruler.
Resource Tree Pop-Up Menu
Appears when right-clicking any item or empty space in Resource Tree.
Customize Context Menus Dynamically
Handle the SchedulerControl.PopupMenuShowing event to customize popup menus at runtime. Use the Menu property to obtain the current pop-up menu. The MenuType property provides information about the current menu type (appointment, time cell, time ruler or appointment drop). See the example below.
private void scheduler_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
//Customize the cell context menu:
if (e.MenuType == ContextMenuType.CellContextMenu)
{
PopupMenu menu = (PopupMenu)e.Menu;
//Change the "New All Day Event" item's caption to "Create All-Day Appointment":
for (int i = 0; i < menu.Items.Count; i++)
{
BarItem menuItem = menu.Items[i] as BarItem;
if (menuItem != null)
{
if (menuItem != null && menuItem.Content.ToString() == "New All Day Event")
{
menuItem.Content = "Create All-Day Appointment";
break;
}
}
}
//Add new menu item:
if (!menu.Items.Contains(myMenuItem))
{
CreateNewItem();
menu.Items.Add(myMenuItem);
}
}
}
private void CreateNewItem()
{
//Create a new menu item:
myMenuItem = new BarButtonItem();
myMenuItem.Name = "customItem";
myMenuItem.Content = "Item Added at Runtime";
myMenuItem.ItemClick += new ItemClickEventHandler(customItem_ItemClick);
}
private void customItem_ItemClick(object sender, ItemClickEventArgs e)
{
// Implement a custom action.
MessageBox.Show(String.Format("{0} is clicked", e.Item.Name));
}
Specify Customization Actions
Add a New Item
The OptionsContextMenu class provides options that allow you to customize context menus. Use the *ContextMenuActions property to access the target context menu’s actions collection. Add an InsertAction to the retrieved collection to add a new item to the context menu. The following code sample inserts two new items to the appointment context menu.
<dxsch:OptionsContextMenu.AppointmentContextMenuActions>
<!--Insert the "Recurrence" item invoking the Recurrence dialog-->
<dxb:InsertAction Index="-1">
<dxb:BarButtonItem Content="Recurrence"
Glyph="{dx:DXImage Image=Recurrence_32x32.png}"
Command="{Binding ElementName=schedulerCommands, Path=OpenRecurrenceWindowCommand}">
</dxb:BarButtonItem>
</dxb:InsertAction>
<!--Insert the check item which converts the selected appointment to an all day event-->
<dxb:InsertAction>
<dxb:BarCheckItem x:Name="allDayCheck"
Content="All-Day Appointment"
Glyph="{dx:DXImage Image=Check_16x16.png}"
CheckedChanged="allDayCheck_CheckedChanged"/>
</dxb:InsertAction>
</dxsch:OptionsContextMenu.AppointmentContextMenuActions>
As a result, the menu appears as follows.
Update an Existing Item
Obtain the context menu’s action collection and add an UpdateAction to it to update any existing context menu item, as shown in the code sample below.
<dxsch:OptionsContextMenu.TimeRulerContextMenuActions>
<!--Hide the "New All Day Event" and "New Recurring Event" items-->
<dxb:UpdateAction ElementName="{x:Static Member=dxsch:DefaultBarItemNames.ContextMenu_Items_TimeRuler_Actions_NewAllDayEvent}"
PropertyName="IsVisible"
Value="False"/>
<dxb:UpdateAction ElementName="{x:Static Member=dxsch:DefaultBarItemNames.ContextMenu_Items_TimeRuler_Actions_NewRecurringEvent}"
PropertyName="IsVisible"
Value="False"/>
<!--Disable the "New Appointment" and "New Recurring Appointment" item-->
<dxb:UpdateAction ElementName="{x:Static Member=dxsch:DefaultBarItemNames.ContextMenu_Items_TimeRuler_Actions_NewAppointment}"
PropertyName="IsEnabled"
Value="False"/>
<dxb:UpdateAction ElementName="{x:Static Member=dxsch:DefaultBarItemNames.ContextMenu_Items_TimeRuler_Actions_NewRecurringAppointment}"
PropertyName="IsEnabled"
Value="False"/>
</dxsch:OptionsContextMenu.TimeRulerContextMenuActions>
The image shows the code execution result.
Remove the Item
Add a RemoveAction to the menu’s action collection to delete any item from the target context menu. The code snippet shows how to delete an item from the appointment drop context menu.
<dxsch:OptionsContextMenu.AppointmentDropContextMenuActions>
<!--Remove the "Copy" item-->
<dxb:RemoveAction ElementName="{x:Static Member=dxsch:DefaultBarItemNames.ContextMenu_Items_AppointmentDrop_Actions_CopyAppointmentsOnDrop}"/>
</dxsch:OptionsContextMenu.AppointmentDropContextMenuActions>
The resulting context menu is shown on the image below.
Create a Custom Context Menu
The OptionsContextMenu.*ContextMenu properties allow you to provide a custom context menu instead of the default one. The code sample below shows how to provide a custom cell pop-up menu shown in the image.
<dxsch:OptionsContextMenu.CellContextMenu>
<dxb:PopupMenu>
<dxb:PopupMenu.Items>
<dxb:BarButtonItem Content="Add Broadcast..."
Glyph="{dx:DXImage Image=Appointment_16x16.png}"
Command="{Binding ElementName=schedulerCommands, Path=ShowNewAppointmentWindowCommand}"/>
<dxb:BarButtonItem Content="Add News Block..."
Glyph="{dx:DXImage Image=RecurringAppointment_16x16.png}"
Command="{Binding ElementName=schedulerCommands, Path=ShowNewRecurringAppointmentWindowCommand}"/>
</dxb:PopupMenu.Items>
</dxb:PopupMenu>
</dxsch:OptionsContextMenu.CellContextMenu>