Data context for mouse event original source element is not of type Task when displaying interruptions within Gantt Chart controls of Gantt Chart Library and Project Management Library for WPF

When you handle mouse events and you check the DataContext property of the original source element routed by the event within a Gantt Chart control from Gantt Chart Library for WPF or Project Management Library for WPF, you may find out that its type is not Task, but TimeInterval instead, when the task is a standard task and AreTaskInterruptionsVisible is set to true to display task interruptions in the chart. This happens because multiple bar rectangles may need to be displayed for a single standard task when interruptions are visible in the view, and each of these rectangles obtains a specific DataContext of its own, as the bars are shown within an ItemsControl control bound to the actual work intervals of the task by default (i.e. as specified within the default StandardTaskTemplate definition).

To obtain the actual Task object in this case, you need to get the visual parent of the source element (i.e. the ItemsControl object containing the task bars), and use the DataContext property of the parent element instead. (In code behind you can use VisualTreeHelper.GetParent method from the WPF core to obtain the visual parent of an element.