New to Telerik UI for WPF? Download free 30-day trial

How to Attach Context Menu to Gantt Event Containers

Environment

Product Version 2019.2.510
Product RadGanttView for WPF

Description

How to display a context menu for the event container elements of RadGanttView.

Solution

Define the context menu on the RadGanttView level and show it only when an EventContainer is clicked. To do this, handle the ContextMenuOpening event.

<telerik:RadGanttView ContextMenuOpening="RadGanttView_ContextMenuOpening"> 
    <telerik:RadContextMenu.ContextMenu> 
        <telerik:RadContextMenu> 
            <telerik:RadMenuItem Header="Click me!" Command="{Binding MyCommand}" /> 
        </telerik:RadContextMenu> 
    </telerik:RadContextMenu.ContextMenu> 
</telerik:RadGanttView> 

private void RadGanttView_ContextMenuOpening(object sender, ContextMenuEventArgs e) 
{ 
    var source = (FrameworkElement)e.OriginalSource; 
    var container = source.ParentOfType<EventContainer>(); 
    if (container == null) 
    { 
        e.Handled = true; 
    } 
} 
Setting e.Handled = true will cancel the menu opening.

See Also

In this article