WPF Gantt - Resources (v20.1)

WPF Team Blog
20 May 2020

As you may already know, our WPF Gantt control (v20.1) allows you to assign resources to individual tasks as needed. Resources can be anything needed to successfully complete an actual task (from individuals and employees to physical equipment and assets).

To help demonstrate this feature, we recently published the following YouTube video.

Video Script: WPF Gantt - Resource Allocation

To learn more, please explore our Startup Plan demo. If you are reading this post on a machine that includes our most recent WPF distribution (v20.1x), please follow this link to start the demo.

Resource Binding

Use the ResourcesSource property to bind the WPF Gantt control to a collection of resources.

<dxgn:GanttControl ItemsSource="{Binding Items}">
    <dxgn:GanttControl.Columns>
        <dxgn:GanttColumn BindTo="Name"/>
        <dxgn:GanttColumn BindTo="StartDate"/>
        <dxgn:GanttColumn BindTo="FinishDate"/>
    </dxgn:GanttControl.Columns>
    <dxgn:GanttControl.View>
        <dxgn:GanttView ResourcesSource="{Binding Resources}" ... />
    </dxgn:GanttControl.View>
</dxgn:GanttControl>

public class StartupBusinessPlanViewModel {
    public List<GanttTask> Items { get; private set; }
    public List<GanttResource> Resources { get; private set; }
    // ...

    public StartupBusinessPlanViewModel() {
        this.Items = CreateData();
        this.Resources = CreateResources();
        // ...
    }

    List<GanttTask> CreateData() {
        var tasks = new List<GanttTask>();
        // ...
        tasks.Add(new GanttTask { Id = 53, 
            ParentId = 48, 
            Name = "Describe strengths, weaknesses, assets and threats", 
            StartDate = new DateTime(2019, 1, 9, 13, 0, 0), 
            FinishDate = new DateTime(2019, 1, 10, 12, 0, 0), 
        });
        tasks.Add(new GanttTask { Id = 54, 
            ParentId = 48, 
            Name = "Estimate sales volume during startup period", 
            StartDate = new DateTime(2019, 1, 10, 13, 0, 0), 
            FinishDate = new DateTime(2019, 1, 11, 12, 0, 0),
        });
        // ...
        return tasks;
    }
    List<GanttResource> CreateResources() {
        var resources = new List<GanttResource>();
        resources.Add(new GanttResource { Name = "Business Advisor", Id = 1 });
        resources.Add(new GanttResource { Name = "Peers", Id = 2 });
        resources.Add(new GanttResource { Name = "Lawyer", Id = 3 });
        resources.Add(new GanttResource { Name = "Government Agency", Id = 4 });
        resources.Add(new GanttResource { Name = "Manager", Id = 5 });
        resources.Add(new GanttResource { Name = "Owners", Id = 6 });
        resources.Add(new GanttResource { Name = "Accountant", Id = 7 });
        resources.Add(new GanttResource { Name = "Banker", Id = 8 });
        resources.Add(new GanttResource { Name = "Information Services", Id = 9 });
        return resources;
    }
}

The code example above uses built-in data classes available in our MVVM library, but you can link our WPF Gantt control to your custom resource classes as well.

Retrieve Resource Dependencies

Once you bind the WPF Gantt control to resources, assign these resources to tasks. Your data source can store resource dependencies in the following ways:

  • in a separate collection, wherein each element contains a task-resource pair.
  • in task objects that contain information about their resources.

Retrieve Resource Dependencies Stored in a Separate Collection

Collection items should contain task and resource fields.


public class GanttResourceLink {
    public object TaskId { get; set; }
    public object ResourceId { get; set; }
}

Bind the ResourceLinksSource property to a collection of resource dependencies (exposed by the ResourceLinks ViewModel property in the code sample below).


<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView ...
                        ResourcesSource="{Binding Resources}"
                        ResourceLinksSource="{Binding ResourceLinks}">
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl>

Retrieve Resource Dependencies Stored in the Task Object

Collection items should contain a resource field.


public class GanttResourceLink {
	public object ResourceId { get; set; }
}

A task object should provide access to a collection of task resources.

public class GanttTask {
    public object Id { get; set; }
	public object ParentId { get; set; }
	public string Name { get; set; }
	public DateTime? StartDate { get; set; }
	public DateTime? FinishDate { get; set; }
	public ObservableCollection<GanttResourceLink> ResourceLinks { get; set; }
	// ...
}

Assign a path to resource dependency data field to the GanttView.ResourceLinksPath property (exposed by the ResourceLinks task property in the code sample below).

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView ...
                        ResourcesSource="{Binding Resources}"
                        ResourceLinksPath="ResourceLinks">
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl>

Feedback

We hope this blog post was helpful. As always, we welcome your thoughts/feedback. Please post a comment below and let us know what you think about the Resource implementation in our WPF Gantt control.

What’s New in v20.1

To explore the scope, breadth and capabilities of our new products/features, please visit: https://www.devexpress.com/Subscriptions/New-2020-1.xml.
No Comments

Please login or register to post comments.