Version

Configuring the Task Duration and Duration Format

Topic Overview

Purpose

This topics describes how you can set task duration and task duration unit using xamGantt™.

Task Duration and Format

Introduction

The duration of a task is the amount of time that the task requires. The task duration value represents a fixed amount of working time.

Task duration may be expressed in various units. The available units for task duration are defined in the ProjectDurationFormat enumeration. Supported unit types are the same that Microsoft Project 2010 supports.

XamGantt assembly defines two custom types for programmatically setting the task duration – ProjectDuration and ManualProjectDuration. A convenient way of setting the project duration is to use the static FromFormatUnits method of ProjectDuration structure.

Duration Unit types

Task duration units can be classified as normal duration units and elapsed duration units. Normal duration units base their calculations on the number of working hours per day. Elapsed duration units base their calculations on 24 hours clock and 7 day week. In other words, when calculating the duration of a 24 hour task using Normal duration units (assuming an 8 hour workday) would be 3 days while the same calculation using Elapsed duration units would be 1 day.

Estimated Duration value

Estimated duration is a current best guess on a task’s duration value. You can set a duration value as an estimate and this will indicate that there is still information pending about the duration of this task.

Note
Note

You can identify estimated duration values by the question mark displayed in the grid cell.

Project Duration

ProjectDuration represents an amount of time for the duration of a task (stored in minutes, as TimeSpan), duration unit (stored as ProjectDurationFormat) and optionally, whether the value is estimated or not.

Project duration depends on several properties of the ProjectSettings class.These properties are used to calculate the number of minutes that a duration represents. They are summarized in the table below:

Property Description

Gets or sets the value indicating the number of days used when calculating a day unit.

Gets or sets the value indicating the number of minutes used when calculating a day unit.

Gets or sets the value indicating the number of minutes used when calculating a week unit.

Note
Note

Changing the value of those properties does not change the duration of tasks already created. Those properties should be set before creating tasks.

Those properties affect the way that duration is displayed.

Code Example: Setting Task Durations

Description

This code example demonstrates how to use the ProjectDuration FromFormatUnits static method to programmatically set the task’s durations. It demonstrates how to set different duration units and values.

Prerequisites

To complete the procedure, you need the following:

  • A project with a reference to the following NuGet package:

    • Infragistics.WPF.Gantt

For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.

Preview

You can see the preview of both compiled and run sample project. It shows xamGantt with four sample tasks created by specifying values for duration and duration units for each of these tasks.

xamGantt Configuring the Task Duration 1.png

Code explanation

You can set the project task duration using the FromFormatUnits method. The code snippet below shows how to create a project task and set its duration.

In C#:

…
new ProjectTask {
    TaskName = "Task 01",
    IsManual = false,
    ManualDuration = ProjectDuration.FromFormatUnits(16, ProjectDurationFormat.Hours)
}…

In Visual Basic:

…
New ProjectTask() With { _
    .TaskName = "Task 01", _
    .IsManual = False, _
    .ManualDuration = ProjectDuration.FromFormatUnits(16, ProjectDurationFormat.Hours) _
}
…

Code

In XAML:

<Grid>
    <ig:XamGantt x:Name="xamGantt" Project="{Binding}" />
</Grid>

In C#:

public Main()
{
    InitializeComponent();
    Loaded += OnMainLoaded;
}

void OnMainLoaded(object sender, RoutedEventArgs rea)
{
    DataContext = GenerateProject();
}

private static Project GenerateProject()
{
    Project project = new Project();
    ProjectTask root = new ProjectTask { TaskName = "Summary", IsManual = false };
    project.RootTask.Tasks.Add(root);
    root.Tasks.Add(new ProjectTask
    { TaskName = "Task 01", IsManual=false, ManualDuration =
        ProjectDuration.FromFormatUnits(16, ProjectDurationFormat.Hours) } );
    root.Tasks.Add(new ProjectTask
    { TaskName = "Task 02", IsManual=false, ManualDuration =
        ProjectDuration.FromFormatUnits(2, ProjectDurationFormat.Days) } );
    root.Tasks.Add(new ProjectTask
    { TaskName = "Task 03", IsManual = false, ManualDuration =
        ProjectDuration.FromFormatUnits(48, ProjectDurationFormat.ElapsedHours) } );
    root.Tasks.Add(new ProjectTask
    { TaskName = "Task 04", IsManual=false, ManualDuration =
        ProjectDuration.FromFormatUnits(2, ProjectDurationFormat.ElapsedDays) } );
    return project;
}

In Visual Basic:

Public Sub New()
      InitializeComponent()
      Loaded = AddressOf OnMainLoaded
End Sub

Private Sub OnMainLoaded(sender As Object, rea As RoutedEventArgs)
      DataContext = GenerateProject()
End Sub

Private Shared Function GenerateProject() As Project
    Dim project As New Project()
    Dim root As New ProjectTask() With {
        .TaskName = "Summary",
        .IsManual = False
    }
    project.RootTask.Tasks.Add(root)
    root.Tasks.Add(New ProjectTask() With {
        .TaskName = "Task 01",
        .IsManual = False,
        .ManualDuration = ProjectDuration.FromFormatUnits(16, ProjectDurationFormat.Hours)
    })
    root.Tasks.Add(New ProjectTask() With {
        .TaskName = "Task 02",
        .IsManual = False,
        .ManualDuration = ProjectDuration.FromFormatUnits(2, ProjectDurationFormat.Days)
    })
    root.Tasks.Add(New ProjectTask() With {
        .TaskName = "Task 03",
        .IsManual = False,
        .ManualDuration = ProjectDuration.FromFormatUnits(48, ProjectDurationFormat.ElapsedHours)
    })
    root.Tasks.Add(New ProjectTask() With {
        .TaskName = "Task 04",
        .IsManual = False,
        .ManualDuration = ProjectDuration.FromFormatUnits(2, ProjectDurationFormat.ElapsedDays)
    })
    Return project
End Function

The following topics provide additional information related to this topic.

Topic Purpose

The topics in this group explain the xamGantt ProjectTask class, its configurable aspects and the main features it provides.

This topic describes the user interactions that can be performed in the grid section of the xamGantt control.