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

Adding Double-Click Behavior to Expand/Collapse GanttTask in RadGanttView for WPF

Environment

Product Telerik UI for WPF
Version 2023.3.1010

Description

How to add a double-click action that expands/collapses the clicked GanttTask in RadGanttView for WPF.

Solution

Subscribe to the MouseDoubleClick event on the RadGanttView control. Then, in the event handler use the ExpandCollapseService of the GanttView control to expand and collapse items. To get the collapse/expand state of the GanttTask objects, you can use the GetItemWrapperByItemKey of the HierarchicalCollectionAdapter.

private void RadGanttView_MouseDoubleClick(object sender, MouseButtonEventArgs args) 
{ 
    var gantt = (RadGanttView)sender; 
    var selectedTask = gantt.SelectedItem as GanttTask;  
    if (selectedTask != null && selectedTask.Children.Count > 0) 
    { 
        HierarchicalItem hierarchicalItem = gantt.ExpandCollapseService.HierarchicalCollectionAdapter.GetItemWrapperByItemKey(selectedTask); 
        if (hierarchicalItem != null) 
        { 
            if (hierarchicalItem.IsExpanded) 
            { 
                gantt.ExpandCollapseService.CollapseItem(gantt.SelectedItem); 
            } 
            else 
            { 
                gantt.ExpandCollapseService.ExpandItem(gantt.SelectedItem); 
            } 
        } 
    }                    
} 
In this article