RadiantQ WPF Gantt
How to listen to end-user beginning (and ending) the task resize or drag operation?
Previous Topic  Next Topic 

How to listen to end-user beginning (and ending) the task resize or drag operation?


There is no direct API that will allow you to listen to these operations. You can however get hold of the underlying Thumbs and listen to the DragStarted and DragCompleted events as follows.


Note: You will however not have control over restricting what the end-user can do here. Also take a look at this topic on how to get notified after the end-user resizes or moves a task.


        public MainWindow()

        {

            InitializeComponent();


            this.ganttControl.ItemsSource = this.GetDataSource();

            this.ganttControl.TemplateApplied += new EventHandler(ganttControl_TemplateApplied);

        }


        void ganttControl_TemplateApplied(object sender, EventArgs e)

        {

            this.ganttControl.GanttChart.AnchorTime = this.ganttControl.ProjectStartDate;

            this.ganttControl.GanttChart.LoadingRow += new EventHandler<GanttChartRowEventArgs>(GanttChart_LoadingRow);

            this.ganttControl.GanttChart.UnloadingRow += new EventHandler<GanttChartRowEventArgs>(GanttChart_UnloadingRow);

        }


       

        void GanttChart_LoadingRow(object sender, GanttChartRowEventArgs e)

        {

            ((GanttTaskItemBar)e.Row).Loaded += new RoutedEventHandler(Bar_Loaded);

        }


        void Bar_Loaded(object sender, RoutedEventArgs e)

        {

            // Listen to DragStarted and DragCompleted of the Thumbs that enable resizing and moving task

            List<Thumb> thumbs = new List<Thumb>();

            Extensions.GetChildren<Thumb>(sender as UIElement, ref thumbs, false, false);

            foreach (Thumb thumb in thumbs)

            {

                if (thumb.Name == "TaskResizeThumb" || thumb.Name == "DepConnectorThumb")

                {

                    thumb.DragStarted += new DragStartedEventHandler(thumb_DragStarted);

                    thumb.DragCompleted += new DragCompletedEventHandler(thumb_DragCompleted);

                }

            }

        }


        void thumb_DragStarted(object sender, DragStartedEventArgs e)

        {

            // Get hold of the underlying task object.

            TaskInfo ti = ((DataBoundActivity)((IActivityView)((Thumb)sender).DataContext).Activity).DataSource as TaskInfo;

            // Do something here like showing a popup.

        }



        void thumb_DragCompleted(object sender, DragCompletedEventArgs e)

        {

            // Undo what was done in DragStarted

        }


        // Unsubscribe to events subscribed in Bar_Loaded.

        void GanttChart_UnloadingRow(object sender, GanttChartRowEventArgs e)

        {

            List<Thumb> thumbs = new List<Thumb>();

            Extensions.GetChildren<Thumb>(e.Row as UIElement, ref thumbs, false, false);

            foreach (Thumb thumb in thumbs)

            {

                if (thumb.Name == "TaskResizeThumb" || thumb.Name == "DepConnectorThumb")

                {

                    thumb.DragStarted -= new DragStartedEventHandler(thumb_DragStarted);

                    thumb.DragCompleted -= new DragCompletedEventHandler(thumb_DragCompleted);

                }

            }

        }



� RadiantQ 2009 - 2019. All Rights Reserved.