这是我实现该功能的代码:
MainPage.xaml.cs
- namespace _5366_Chart
- {
- public partial class MainPage : Page
- {
- public MainPage()
- {
- InitializeComponent();
- var _tournament = GetDataSource();
- c1OrgChart1.Header = _tournament;
- }
- public static Team GetDataSource()
- {
- Team header = Date().Where(t => t.ID == 1).FirstOrDefault();
- OrgStaff(header);
- return header;
- }
- public static void OrgStaff(Team team)
- {
- var staff = Date().Where(e => e.Fid == team.ID);
- foreach (Team item in staff)
- {
- OrgStaff(item);
- team.Staff.Add(item);
- }
- }
- public static List<Team> Date()
- {
- List<Team> source = new List<Team>();
- source.Add(new Team() { ID = 1, Name = "刘华强", Position = "董事长", Fid = 0 });
- source.Add(new Team() { ID = 2, Name = "赵晓华", Position = "产品经理", Fid = 1 });
- source.Add(new Team() { ID = 3, Name = "刘宗敏", Position = "项目经理", Fid = 1 });
- source.Add(new Team() { ID = 4, Name = "林志玲", Position = "产品经理秘书", Fid = 2 });
- source.Add(new Team() { ID = 5, Name = "刘德华", Position = "技术员", Fid = 3 });
- source.Add(new Team() { ID = 6, Name = "张学友", Position = "技术员", Fid = 3 });
- source.Add(new Team() { ID = 7, Name = "谭咏麟", Position = "初级技术员", Fid = 6 });
- return source;
- }
- }
- public class Team
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Position { get; set; }
- public int Fid { get; set; }
- public override string ToString()
- {
- return Position + ": " + Name;
- }
- private List<Team> _staff = new List<Team>();
- public List<Team> Staff
- {
- get { return _staff; }
- set { _staff = value; }
- }
- }
- }
复制代码
|