Skip to main content

GanttView.ResourceLinksSelector Property

Gets or sets an object that chooses resource links relative to a task object based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.Gantt

Assembly: DevExpress.Xpf.Gantt.v23.2.dll

NuGet Package: DevExpress.Wpf.Gantt

Declaration

public IResourceLinksSelector ResourceLinksSelector { get; set; }

Property Value

Type Description
IResourceLinksSelector

An object that chooses resource links based on custom logic.

Remarks

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.Columns>
        <dxgn:GanttColumn BindTo="Name" />
        <dxgn:GanttColumn BindTo="StartDate" />
        <dxgn:GanttColumn BindTo="FinishDate" />
        <dxgn:GanttColumn BindTo="ResourceLinks" />
    </dxgn:GanttControl.Columns>
    <dxgn:GanttControl.View>
        <dxgn:GanttView
            AutoExpandAllNodes="True"
            AllowEditing="False"
            ResourcesSource="{Binding Resources}"
            ResourceLinksSelector="{local:ResourceLinksSelector}">
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl> 
public class ResourceLinksSelector : MarkupExtension, DevExpress.Xpf.Gantt.IResourceLinksSelector {
    public override object ProvideValue(IServiceProvider serviceProvider) {
        return this;
    }
    public IEnumerable SelectResourceLinks(object item) {
        var task = (GanttTask)item;
        if(task.Tag == null)
            return null;
        return ((string)task.Tag)
            .Split(';')
            .Select(x => new GanttResourceLink() { ResourceId = Convert.ToInt32(x) })
            .ToList();
    }
} 
Show View Model
public class ProjectTaskViewModel {
    public ProjectTaskViewModel() {
        Tasks = new ObservableCollection<GanttTask> {
            new GanttTask() {
                Id = 0,
                Name = "Add a new feature",
                StartDate = DateTime.Now.AddDays(-1),
                FinishDate = DateTime.Now.AddDays(6)
            },

            new GanttTask() {
                Id = 1,
                ParentId = 0,
                Name = "Write the code",
                StartDate = DateTime.Now.AddDays(-1),
                FinishDate = DateTime.Now.AddDays(2),
                Tag = "1"
            },

            new GanttTask() {
                Id = 2,
                ParentId = 0,
                Name = "Write the docs",
                StartDate = DateTime.Now.AddDays(2),
                FinishDate = DateTime.Now.AddDays(5),
                Tag = "2"
            },

            new GanttTask() {
                Id = 3,
                ParentId = 0,
                Name = "Test the new feature",
                StartDate = DateTime.Now.AddDays(2),
                FinishDate = DateTime.Now.AddDays(5),
                Tag = "3"
            },

            new GanttTask() {
                Id = 4,
                ParentId = 0,
                Name = "Release the new feature",
                StartDate = DateTime.Now.AddDays(5),
                FinishDate = DateTime.Now.AddDays(5),
                Tag = "1;2;3;4"
            }
        };

        Resources = new ObservableCollection<GanttResource> {
            new GanttResource() { Name = "Developers", Id = 1 },
            new GanttResource() { Name = "Technical Writers", Id = 2 },
            new GanttResource() { Name = "Testers", Id = 3 },
            new GanttResource() { Name = "Product Manager", Id = 4 }
        };

    }
    public ObservableCollection<GanttTask> Tasks { get; }
    public ObservableCollection<GanttResource> Resources { get; }
} 

See Also