原創|使用教程|編輯:龔雪|2020-05-28 13:40:06.123|閱讀 432 次
概述:WPF Gantt控件(v20.1)允許您根據需要將資源分配給各個任務,資源可以是成功完成實際任務所需的一切(從個人和員工到物理設備和資產)。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
下載DevExpress v20.1完整版 DevExpress v20.1漢化資源獲取
通過DevExpress WPF Controls,您能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。
WPF Gantt控件(v20.1)允許您根據需要將資源分配給各個任務,資源可以是成功完成實際任務所需的一切(從個人和員工到物理設備和資產)。
 
使用 屬性將WPF Gantt控件綁定到資源集合。
<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;
}
}
上面的代碼示例使用MVVM庫中提供的內置數據類,但是您也可以將WPF Gantt控件鏈接到您的自定義資源類。
將WPF甘特圖控件綁定到資源后,將這些資源分配給任務。 您的數據源可以通過以下方式存儲資源依賴性:
檢索存儲在單獨集合中的資源依賴項
收集項目應包含任務和資源字段。
public class GanttResourceLink {
public object TaskId { get; set; }
public object ResourceId { get; set; }
}
將ResourceLinksSource屬性綁定到資源依賴項的集合(由下面的代碼示例中的ResourceLinks ViewModel屬性公開)。
<dxgn:GanttControl ItemsSource="{Binding Tasks}">
<dxgn:GanttControl.View>
<dxgn:GanttView ...
ResourcesSource="{Binding Resources}"
ResourceLinksSource="{Binding ResourceLinks}">
</dxgn:GanttView>
</dxgn:GanttControl.View>
</dxgn:GanttControl>
檢索存儲在任務對象中的資源依賴關系
收集項目應包含一個資源字段。
public class GanttResourceLink {
public object ResourceId { get; set; }
}
任務對象應提供對任務資源集合的訪問。
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; }
// ...
}
將資源依賴關系數據字段的路徑分配給GanttView.ResourceLinksPath屬性(由下面的代碼示例中的ResourceLinks任務屬性公開)。
<dxgn:GanttControl ItemsSource="{Binding Tasks}">
<dxgn:GanttControl.View>
<dxgn:GanttView ...
ResourcesSource="{Binding Resources}"
ResourceLinksPath="ResourceLinks">
</dxgn:GanttView>
</dxgn:GanttControl.View>
</dxgn:GanttControl>
DevExpress 5月線上公開課報名火熱開啟,教你入門報表(Report)控件
DevExpress技術交流群:775869749 歡迎一起進群討論
掃描關注DevExpress中文網微信公眾號,及時獲取最新動態及最新資訊
 
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都網