RadiantQ WPF Gantt
ContextMenus
Previous Topic  Next Topic 

ContextMenus


Sample (Samples\ProjectGantt\UserInteraction\CustomizingMenus) illustrates adding ContextMenus to GanttControl area.



Gantt Table Context Menus


You can easily add custom ContextMenus to the DataGridRow representing each row in the GanttTable. You can do so as follows in XAML, under the resources section:


            <Style TargetType="{x:Type DataGridRow}">

                <Setter Property="ContextMenu" Value="{StaticResource contextMenu}">

                </Setter>

            </Style>


Resultant context menu:

ContextMenu for each DataGridRow


In the Click event handlers, you can access the bound Activity and data bound task as follows:


        private void deleteTask_Click(object sender, RoutedEventArgs e)

        {

            // If the selected activity is a parent then all it's children will have to be removed too.

            // So, always use this pattern.

            IActivity selectedActivity = this.ganttControl.SelectedActivity;

            // This will remove the activities from the Gantt UI.

            // You should then remove the corresponding bound items in the data source.

            List<IActivity> allRemoved = this.ganttControl.RemoveActivity(selectedActivity.ID);


            foreach (IActivity removedActivity in allRemoved)

            {

                this.dataSource.Remove(((DataBoundActivity)removedActivity).DataSource as TaskInfo);

            }

        }


Gantt Chart Task Bar Context Menu


Associate a ContextMenu with the GanttTaskItemBar type to show context menus on right clicking on each bar as follows (in XAML, under resources):


            <Style TargetType="{x:Type ganttview:GanttTaskItemBar}">

                <Setter Property="ContextMenu" Value="{StaticResource contextMenu2}">

                </Setter>

            </Style>

Custom ContextMenu associated with task bars


In the Click event handler, you can access the activity and the bound task item as follows:


        private void customTask_Click(object sender, RoutedEventArgs e)

        {

            MenuItem mi = e.OriginalSource as MenuItem;

            ContextMenu cm = mi.Parent as ContextMenu;

            IActivityView activityView = cm.DataContext as IActivityView;

            MessageBox.Show(string.Format("TaskInfo context in chart: Name: {0}; StartTime: {1}", activityView.Activity.ActivityName, activityView.Activity.StartTime.ToShortDateString()));

        }




� RadiantQ 2009 - 2019. All Rights Reserved.