[C#/SILVERLIGHT] CollectionViewSource 엘리먼트 : 계층적 데이터 바인딩 하기
■ CollectionViewSource 엘리먼트를 사용해 계층적 데이터를 바인딩하는 방법을 보여준다. ▶ Team.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/// <summary> /// 팀 /// </summary> public class Team { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion } |
▶ Division.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
using System; using System.Collections.ObjectModel; /// <summary> /// 부문 /// </summary> public class Division { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 팀 컬렉션 - TeamCollection /// <summary> /// 팀 컬렉션 /// </summary> public ObservableCollection<Team> TeamCollection { get; set; } #endregion } |
▶ League.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
using System; using System.Collections.ObjectModel; /// <summary> /// 리그 /// </summary> public class League { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 부문 컬렉션 - DivisionCollection /// <summary> /// 부문 컬렉션 /// </summary> public ObservableCollection<Division> DivisionCollection { get; set; } #endregion } |
▶ LeagueCollection.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System; using System.Collections.ObjectModel; /// <summary> /// 리그 컬렉션 /// </summary> public class LeagueCollection : ObservableCollection<League> { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - LeagueCollection() /// <summary> /// 생성자 /// </summary> public LeagueCollection() { for(int x = 1; x < 3; x++) { League league = new League() { Name = "League " + x, DivisionCollection = new ObservableCollection<Division>() }; for(int y = 1; y < 4; y++) { Division division = new Division() { Name = string.Format("Division {0}-{1}", x, y), TeamCollection = new ObservableCollection<Team>() }; for(int z = 1; z < 5; z++) { Team team = new Team() { Name = string.Format("Team {0}-{1}-{2}", x, y, z) }; division.TeamCollection.Add(pTeam); } league.DivisionCollection.Add(pDivision); } Add(league); } } #endregion } |
▶