Skip to main content

Task Dependencies

  • 5 minutes to read

The GanttControl can show relationships between tasks. These relationships are called task dependencies. They indicate dependency criteria based on which tasks begin and end in relation to each other. For example, the FinishToStart dependency means that the second task may not start before the first task is finished.

The following task dependency types are available:

Note

To specify task dependencies, you must specify the GanttView.KeyFieldName property value.

Retrieve Task Dependencies

In your data source, the task dependencies can be stored in any of the following ways:

  • Task dependencies are stored in a separate collection: each of the collection elements stores Successor-Predecessor pair.
  • Task dependencies are stored in the task objects: successor tasks store information about their predecessors.

The GanttControl supports both of them.

Retrieve Task Dependencies Stored in a Separate Collection

If you store task dependencies in a separate collection, the collection items should contain the following fields:

  1. predecessor task or its Id
  2. successor task or its Id
  3. task dependency type: a PredecessorLinkType enumeration value.

    If the task dependency type is not specified, the FinishToStart dependency type is used.

The code sample below demonstrates the data model that represents task dependencies.

public class Link {
    // Specifies the predecessor task's Id
    public int PredecessorId { get; set; }
    // Specifies the successor task's Id
    public int SuccessorId { get; set; }
    // Specifies the task dependency type (FinishToStart, FinishToFinish, etc.)
    public PredecessorLinkType Type { get; set; }
    // Specifies the time lag between two tasks
    public System.TimeSpan TimeLag { get; set; }
} 

To retrieve task dependencies from a data source, do the following:

  1. Bind the GanttView.PredecessorLinksSource property to a collection of task dependencies (exposed by the Dependencies ViewModel property in the code sample below).
  2. Specify the mappings to dependency objects using the GanttView.PredecessorLinkMappings property.

The code sample below illustrates a GanttControl bound to a data source and to a collection of task dependencies.

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.Columns>
        <dxgn:GanttColumn BindTo="Name"/>
        <dxgn:GanttColumn BindTo="StartDate"/>
        <dxgn:GanttColumn BindTo="FinishDate"/>
    </dxgn:GanttControl.Columns>
    <dxgn:GanttControl.View>
        <dxgn:GanttView
            AutoExpandAllNodes="True"
            KeyFieldName="Id"
            ChildNodesPath="Children"
            StartDateMapping="Start"
            FinishDateMapping="Finish"
            NameMapping="Name"
            TreeDerivationMode="ChildNodesSelector"
            PredecessorLinksSource="{Binding Dependencies}">
            <dxgn:GanttView.PredecessorLinkMappings>
                <dxgn:GanttPredecessorLinkMappings
                    PredecessorTask="PredecessorId"
                    Task="SuccessorId"
                    LinkType="Type"
                    Lag="TimeLag"/>
            </dxgn:GanttView.PredecessorLinkMappings>
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl>

Retrieve Task Dependencies Stored in the Task Object

If you store task’s dependencies in the task object, the collection items should contain the following fields:

  1. predecessor task or its Id
  2. task dependency type: a PredecessorLinkType enumeration value.

    If the task dependency type is not specified, the FinishToStart dependency type is used.

The code sample below demonstrates the data model that represents task dependencies.

public class Link {
    // Specifies the predecessor task's Id
    public int PredecessorId { get; set; }
    // Specifies the task dependency type (FinishToStart, FinishToFinish, etc.)
    public PredecessorLinkType Type { get; set; }
} 

If you store task’s dependencies in the task object, the task object should provide access to a collection of task’s dependencies, like in the code sample below:

public class Task {
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Start { get; set; }
    public DateTime Finish { get; set; }
    public ObservableCollection<Task> Children { get; } = new ObservableCollection<Task>();
    public ObservableCollection<Link> DependencyLinks { get; } = new ObservableCollection<Link>();
} 

To retrieve task dependencies from task objects, do the following:

  1. Provide a path to task dependency data field to the GanttView.PredecessorLinksPath property (exposed by the DependencyLinks task property in the code sample below).
  2. Specify the mappings to dependency objects using the GanttView.PredecessorLinkMappings property.

The code sample below illustrates a GanttControl bound to a data source and to a collection of task dependencies.

 <dxgn:GanttControl ItemsSource="{Binding Tasks}">
     <dxgn:GanttControl.Columns>
         <dxgn:GanttColumn BindTo="Name"/>
         <dxgn:GanttColumn BindTo="StartDate"/>
         <dxgn:GanttColumn BindTo="FinishDate"/>
     </dxgn:GanttControl.Columns>
     <dxgn:GanttControl.View>
         <dxgn:GanttView
             AutoExpandAllNodes="True"
             ChildNodesPath="Children"
             StartDateMapping="Start"
             FinishDateMapping="Finish"
             NameMapping="Name"
             TreeDerivationMode="ChildNodesSelector"
             PredecessorLinksPath="DependencyLinks">
             <dxgn:GanttView.PredecessorLinkMappings>
                 <dxgn:GanttPredecessorLinkMappings
                     PredecessorTask="Task"
                     LinkType="Type"/>
             </dxgn:GanttView.PredecessorLinkMappings>
         </dxgn:GanttView>
     </dxgn:GanttControl.View>
 </dxgn:GanttControl>

Using the Default Dependency Type (FinishToStart)

You can simplify your ViewModel if your tasks use only the FinishToStart dependency type.

In this case, your task objects should provide access to a collection of task predecessors (or their Id’s), like in the code sample below.

public class Task {
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Start { get; set; }
    public DateTime Finish { get; set; }
    public ObservableCollection<Task> Children { get; } = new ObservableCollection<Task>();
    // Each tasks have a collection of its predecessor tasks (identified by Id's)
    public ObservableCollection<int> PredecessorIds { get; } = new ObservableCollection<int>();
}

To retrieve task dependencies from task objects, do the following:

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    ...
    <dxgn:GanttControl.View>
        <dxgn:GanttView
            AutoExpandAllNodes="True"
            KeyFieldName="Id"
            ChildNodesPath="Children"
            StartDateMapping="Start"
            FinishDateMapping="Finish"
            NameMapping="Name"
            PredecessorLinksPath="PredecessorIds" 
            TreeDerivationMode="ChildNodesSelector">
            <dxgn:GanttView.PredecessorLinkMappings>
                <dxgn:GanttPredecessorLinkMappings PredecessorTask="." />
            </dxgn:GanttView.PredecessorLinkMappings>
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl>