Loading tasks with preinitialized duration and percent complete values

into Gantt Chart Light Library components for WPF

DlhSoft
Gantt chart libraries
2 min readJul 3, 2023

--

If you use GanttChartDataGrid component from DlhSoft Gantt Chart Light Library for WPF you probably know already that items’ schedule is defined by Start, Finish and CompletedFinish property values. (This, in order to ensure optimal performance.)

Sometimes, however, you have durations (or effort values) and completion percentages persisted, and at component initialization time you’ll need to convert them to absolute DateTime values, accordingly.

Don’t worry, though: the component does provide with some shortcut methods (GetFinish and GetCompletedFinish) that you can use to compute what’s needed; remember, however, to ensure the internals are initialized too before trying to use them, by calling ApplyTemplate as shown below:

// Ensure component internals are ready
GanttChartDataGrid.ApplyTemplate();

// A loop to pre-initialize your items
var items = new ObservableCollection<GanttChartItem>();
while (...)
{
var item = new GanttChartItem { ... };

item.Finish = GanttChartDataGrid.GetFinish(start, duration);
item.CompletedFinish = GanttChartDataGrid.GetCompletedFinish(start, percentCompleted / 100.0, item.Finish);

items.Add(item);
}

// Finally, load the items into the Gantt chart component
GanttChartDataGrid.Items = items;

Note: optionally, you can also pass a final argument of type Schedule to the Get functions above, if needed, as by default the algorithm to compute the requested values would use the schedule set up on the component itself.

Also note: GanttChartView component provides similar methods, in case you don’t need the DataGrid.

--

--