■ TreeListControl 클래스에서 HierarchicalDataTemplate 리소스 객체의 암시적 데이터 타입 설정을 사용해 계층적 트리를 구축하는 방법을 보여준다.
▶ BaseObject.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
using System.ComponentModel; namespace TestProject { /// <summary> /// 기본 객체 /// </summary> public class BaseObject : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 - PropertyChanged /// <summary> /// 속성 변경시 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 명칭 /// </summary> private string name; /// <summary> /// 실행자 /// </summary> private string executor; /// <summary> /// 소유자 진행 객체 /// </summary> private ProgressingObject ownerProgressingObject; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get { return this.name; } set { if(this.name == value) { return; } this.name = value; OnPropertyChanged("Name"); } } #endregion #region 실행자 - Executor /// <summary> /// 실행자 /// </summary> public string Executor { get { return this.executor; } set { if(ReferenceEquals(this.executor, value)) { return; } this.executor = value; OnPropertyChanged("Executor"); } } #endregion #region 소유자 진행 객체 - OwnerProgressingObject /// <summary> /// 소유자 진행 객체 /// </summary> public ProgressingObject OwnerProgressingObject { get { return this.ownerProgressingObject; } set { if(ReferenceEquals(this.ownerProgressingObject, value)) { return; } this.ownerProgressingObject = value; OnPropertyChanged("OwnerProgressingObject"); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return this.name; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 속성 변경시 처리하기 - OnPropertyChanged(propertyName) /// <summary> /// 속성 변경시 처리하기 /// </summary> /// <param name="propertyName">속성명</param> protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } } |
▶ ProgressingObject.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
namespace TestProject { /// <summary> /// 진행 객체 /// </summary> public class ProgressingObject : BaseObject { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 진행도 /// </summary> private int progress; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행도 - Progress /// <summary> /// 진행도 /// </summary> public int Progress { get { return this.progress; } set { if(ReferenceEquals(this.progress, value)) { return; } this.progress = value; OnPropertyChanged("Progress"); if(OwnerProgressingObject != null) { OwnerProgressingObject.UpdateProgress(); } } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행도 계산하기 - UpdateProgress() /// <summary> /// 진행도 갱신하기 /// </summary> public virtual void UpdateProgress() { } #endregion } } |
▶ ProjectObject.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System.Collections.ObjectModel; namespace TestProject { /// <summary> /// 프로젝트 객체 /// </summary> public class ProjectObject : ProgressingObject { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 프로젝트 스테이지 컬렉션 - ProjectStageCollection /// <summary> /// 프로젝트 스테이지 컬렉션 /// </summary> public ObservableCollection<ProjectStage> ProjectStageCollection { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ProjectObject() /// <summary> /// 생성자 /// </summary> public ProjectObject() { ProjectStageCollection = new ObservableCollection<ProjectStage>(); ProjectStageCollection.CollectionChanged += (sender, e) => { UpdateProgress(); }; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행도 갱신하기 - UpdateProgress() /// <summary> /// 진행도 갱신하기 /// </summary> public override void UpdateProgress() { int completed = 0; int summary = 0; if(ProjectStageCollection != null) { foreach(ProjectStage projectStage in ProjectStageCollection) { summary++; if(projectStage.Progress >= 100) { completed++; } } } if(summary == 0) { Progress = 100; } else { Progress = completed * 100 / summary; } } #endregion } } |
▶ ProjectStage.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System.Collections.ObjectModel; namespace TestProject { /// <summary> /// 프로젝트 스테이지 /// </summary> public class ProjectStage : ProgressingObject { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 과제 컬렉션 - TaskCollection /// <summary> /// 과제 컬렉션 /// </summary> public ObservableCollection<Task> TaskCollection { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ProjectStage() /// <summary> /// 생성자 /// </summary> public ProjectStage() { TaskCollection = new ObservableCollection<Task>(); TaskCollection.CollectionChanged += (sender, e) => { this.UpdateProgress(); }; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 진행도 갱신하기 - UpdateProgress() /// <summary> /// 진행도 갱신하기 /// </summary> public override void UpdateProgress() { int completed = 0; int summary = 0; if(TaskCollection != null) { foreach(Task task in TaskCollection) { summary++; if(task.State == null || task.State.Value == 2) { completed++; } } } if(summary == 0) { Progress = 100; } else { Progress = completed * 100 / summary; } } #endregion } } |
▶ State.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
using System; using System.Collections.Generic; using System.Windows.Media; namespace TestProject { /// <summary> /// 상태 /// </summary> public class State : IComparable { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이미지 소스 - ImageSource /// <summary> /// 이미지 소스 /// </summary> public ImageSource ImageSource { get; set; } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public string Text { get; set; } #endregion #region 값 - Value /// <summary> /// 값 /// </summary> public int Value { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return Text; } #endregion #region 비교하기 - CompareTo(sourceObject) /// <summary> /// 비교하기 /// </summary> /// <param name="sourceObject">소스 객체</param> /// <returns>비교 결과</returns> public int CompareTo(object sourceObject) { return Comparer<int>.Default.Compare(Value, ((State)sourceObject).Value); } #endregion } } |
▶ StateList.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 56 57 58 59 60 61 62 63 64 65 66 67 68 |
using System; using System.Collections.Generic; using System.Windows.Media.Imaging; using System.Windows.Media; namespace TestProject { /// <summary> /// 상태 리스트 /// </summary> public class StateList : List<State> { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 상태 리스트 /// </summary> private static List<State> _stateList; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 데이터 소스 - DataSource /// <summary> /// 데이터 소스 /// </summary> public static List<State> DataSource { get { if(_stateList == null) { _stateList = new List<State>(); _stateList.Add(new State() { Text = "Not started", Value = 0, ImageSource = new BitmapImage(new Uri("Image/state_notstarted.png", UriKind.Relative)) }); _stateList.Add(new State() { Text = "In progress", Value = 1, ImageSource = new BitmapImage(new Uri("Image/state_inprogress.png", UriKind.Relative)) }); _stateList.Add(new State() { Text = "Completed" , Value = 2, ImageSource = new BitmapImage(new Uri("Image/state_completed.png" , UriKind.Relative)) }); } return _stateList; } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 이미지 소스 - ImageSource /// <summary> /// 이미지 소스 /// </summary> public ImageSource ImageSource { get; set; } #endregion } } |
▶ Task.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
using System; namespace TestProject { /// <summary> /// 과제 /// </summary> public class Task : BaseObject { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 시작일 /// </summary> private DateTime startDate; /// <summary> /// 종료일 /// </summary> private DateTime endDate; /// <summary> /// 상태 /// </summary> private State state; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 시작일 - StartDate /// <summary> /// 시작일 /// </summary> public DateTime StartDate { get { return this.startDate; } set { if(this.startDate == value) { return; } this.startDate = value; OnPropertyChanged("StartDate"); } } #endregion #region 종료일 - EndDate /// <summary> /// 종료일 /// </summary> public DateTime EndDate { get { return this.endDate; } set { if(this.endDate == value) { return; } this.endDate = value; OnPropertyChanged("EndDate"); } } #endregion #region 상태 - State /// <summary> /// 상태 /// </summary> public State State { get { return this.state; } set { if(ReferenceEquals(this.state, value)) { return; } this.state = value; OnPropertyChanged("State"); if(OwnerProgressingObject != null) { OwnerProgressingObject.UpdateProgress(); } } } #endregion } } |
▶ ViewModel.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
using System; using System.Collections.ObjectModel; namespace TestProject { /// <summary> /// 뷰 모델 /// </summary> public class ViewModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 프로젝트 객체 컬렉션 - ProjectObjectCollection /// <summary> /// 프로젝트 객체 컬렉션 /// </summary> public ObservableCollection<ProjectObject> ProjectObjectCollection { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewModel() /// <summary> /// 생성자 /// </summary> public ViewModel() { ProjectObjectCollection = InitializeProjectObjectCollection(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Betaron 프로젝트 객체 초기화 하기 - InitializeBetaronProjectObject(projectObject) /// <summary> /// Betaron 프로젝트 객체 초기화 하기 /// </summary> /// <param name="projectObject">프로젝트 객체</param> private void InitializeBetaronProjectObject(ProjectObject projectObject) { projectObject.Executor = "Mcfadyen Ball"; ProjectStage projectStage21 = new ProjectStage() { Name = "Information Gathering", Executor = "Kaiden Savastano", OwnerProgressingObject = projectObject }; projectStage21.TaskCollection.Add ( new Task() { Name = "Market research", Executor = "Carmine Then", StartDate = new DateTime(2011, 10, 1), EndDate = new DateTime(2011, 10, 5 ), State = StateList.DataSource[2], OwnerProgressingObject = projectStage21 } ); projectStage21.TaskCollection.Add ( new Task() { Name = "Making specification", Executor = "Seto Kober", StartDate = new DateTime(2011, 10, 5), EndDate = new DateTime(2011, 10, 10), State = StateList.DataSource[1], OwnerProgressingObject = projectStage21 } ); ProjectStage projectStage22 = new ProjectStage() { Name = "Planning", Executor = "Manley Difrancesco", OwnerProgressingObject = projectObject }; projectStage22.TaskCollection.Add ( new Task() { Name = "Documentation", Executor = "Martez Gollin", StartDate = new DateTime(2011, 10, 15), EndDate = new DateTime(2011, 10, 16), State = StateList.DataSource[0], OwnerProgressingObject = projectStage22 } ); ProjectStage projectStage23 = new ProjectStage() { Name = "Design", Executor = "Clint Mary", OwnerProgressingObject = projectObject }; projectStage23.TaskCollection.Add ( new Task() { Name = "Design of a web pages", Executor = "Gasper Hartsell", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage23 } ); projectStage23.TaskCollection.Add ( new Task() { Name = "Pages layout", Executor = "Shirish Huminski", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage23 } ); ProjectStage projectStage24 = new ProjectStage() { Name = "Development", Executor = "Edwin Thone", OwnerProgressingObject = projectObject }; projectStage24.TaskCollection.Add ( new Task() { Name = "Design", Executor = "Zarko Knill", StartDate = new DateTime(2011, 10, 27), EndDate = new DateTime(2011, 10, 28), State = StateList.DataSource[0], OwnerProgressingObject = projectStage24 } ); projectStage24.TaskCollection.Add ( new Task() { Name = "Coding", Executor = "Harley Kirckof", StartDate = new DateTime(2011, 10, 29), EndDate = new DateTime(2011, 10, 30), State = StateList.DataSource[0], OwnerProgressingObject = projectStage24 } ); ProjectStage projectStage25 = new ProjectStage() { Name = "Testing and Delivery", Executor = "Boucher Hislop", OwnerProgressingObject = projectObject }; projectStage25.TaskCollection.Add ( new Task() { Name = "Testing", Executor = "Sarah Ragas", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage25 } ); projectStage25.TaskCollection.Add ( new Task() { Name = "Content", Executor = "Rashid Terinoni", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage25 } ); projectObject.ProjectStageCollection.Add(projectStage21); projectObject.ProjectStageCollection.Add(projectStage22); projectObject.ProjectStageCollection.Add(projectStage23); projectObject.ProjectStageCollection.Add(projectStage24); projectObject.ProjectStageCollection.Add(projectStage25); } #endregion #region Stantone 프로젝트 객체 초기화 하기 - InitializeStantoneProjectObject(projectObject) /// <summary> /// Stantone 프로젝트 객체 초기화 하기 /// </summary> /// <param name="projectObject">프로젝트 객체</param> private void InitializeStantoneProjectObject(ProjectObject projectObject) { projectObject.Executor = "Ruben Ackerman"; ProjectStage projectStage11 = new ProjectStage() { Name = "Information Gathering", Executor = "Huyen Trinklein", OwnerProgressingObject = projectObject }; projectStage11.TaskCollection.Add ( new Task() { Name = "Market research", Executor = "Tanner Crittendon", StartDate = new DateTime(2011, 10, 1), EndDate = new DateTime(2011, 10, 5 ), State = StateList.DataSource[2], OwnerProgressingObject = projectStage11 } ); projectStage11.TaskCollection.Add ( new Task() { Name = "Making specification", Executor = "Carmine Then", StartDate = new DateTime(2011, 10, 5), EndDate = new DateTime(2011, 10, 10), State = StateList.DataSource[2], OwnerProgressingObject = projectStage11 } ); ProjectStage projectStage12 = new ProjectStage() { Name = "Planning", Executor = "Alfredo Sookoo", OwnerProgressingObject = projectObject }; projectStage12.TaskCollection.Add ( new Task() { Name = "Documentation", Executor = "Gorf Wobbe", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[2], OwnerProgressingObject = projectStage12 } ); ProjectStage projectStage13 = new ProjectStage() { Name = "Design", Executor = "Saphire Plump", OwnerProgressingObject = projectObject }; projectStage13.TaskCollection.Add ( new Task() { Name = "Design of a web pages", Executor = "Dominic Minden", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[1], OwnerProgressingObject = projectStage13 } ); projectStage13.TaskCollection.Add ( new Task() { Name = "Pages layout", Executor = "Pinkerton Trezise", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[1], OwnerProgressingObject = projectStage13 } ); ProjectStage projectStage14 = new ProjectStage() { Name = "Development", Executor = "Lauren Partain", OwnerProgressingObject = projectObject }; projectStage14.TaskCollection.Add ( new Task() { Name = "Design", Executor = "Delilah Beamer", StartDate = new DateTime(2011, 10, 23), EndDate = new DateTime(2011, 10, 24), State = StateList.DataSource[1], OwnerProgressingObject = projectStage14 } ); projectStage14.TaskCollection.Add ( new Task() { Name = "Coding", Executor = "Dunaway Dupriest", StartDate = new DateTime(2011, 10, 25), EndDate = new DateTime(2011, 10, 26), State = StateList.DataSource[0], OwnerProgressingObject = projectStage14 } ); ProjectStage projectStage15 = new ProjectStage() { Name = "Testing and Delivery", Executor = "Christos Arrant", OwnerProgressingObject = projectObject }; projectStage15.TaskCollection.Add ( new Task() { Name = "Testing", Executor = "Grice Ohora", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage15 } ); projectStage15.TaskCollection.Add ( new Task() { Name = "Content", Executor = "Christos Arrant", StartDate = new DateTime(2011, 10, 13), EndDate = new DateTime(2011, 10, 14), State = StateList.DataSource[0], OwnerProgressingObject = projectStage15 } ); projectObject.ProjectStageCollection.Add(projectStage11); projectObject.ProjectStageCollection.Add(projectStage12); projectObject.ProjectStageCollection.Add(projectStage13); projectObject.ProjectStageCollection.Add(projectStage14); projectObject.ProjectStageCollection.Add(projectStage15); } #endregion #region 프로젝트 객체 컬렉션 초기화 하기 - InitializeProjectObjectCollection() /// <summary> /// 프로젝트 객체 컬렉션 초기화 하기 /// </summary> /// <returns>프로젝트 객체 컬렉션</returns> private ObservableCollection<ProjectObject> InitializeProjectObjectCollection() { ObservableCollection<ProjectObject> projectObjectCollection = new ObservableCollection<ProjectObject>(); ProjectObject betaronProjectObject = new ProjectObject() { Name = "Project : Betaron" }; ProjectObject stantoneProjectObject = new ProjectObject() { Name = "Project : Stanton" }; InitializeBetaronProjectObject (betaronProjectObject ); InitializeStantoneProjectObject(stantoneProjectObject); projectObjectCollection.Add(betaronProjectObject ); projectObjectCollection.Add(stantoneProjectObject); return projectObjectCollection; } #endregion } } |
▶ MainWindow.xaml
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="HierarchicalDataTemplate를 통해 트리 구축하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <ResourceDictionary> <local:ViewModel x:Key="ViewModelKey" /> <local:StateList x:Key="StateListKey" /> <HierarchicalDataTemplate DataType="{x:Type local:ProjectObject}" ItemsSource="{Binding ProjectStageCollection}"> <dx:MeasurePixelSnapper> <StackPanel Orientation="Vertical"> <ContentPresenter x:Name="defaultRowContentContentPresenter" ContentTemplate="{Binding View.DefaultDataRowTemplate}" Content="{Binding}" /> <Border HorizontalAlignment="Stretch" VerticalAlignment="Center" BorderThickness="0 1 0 0" BorderBrush="#ffc3cedc" Padding="2"> <ProgressBar Height="5" Minimum="0" Maximum="100" Value="{Binding Row.Progress}" /> </Border> </StackPanel> </dx:MeasurePixelSnapper> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type local:ProjectStage}" ItemsSource="{Binding TaskCollection}"> <dx:MeasurePixelSnapper> <StackPanel Orientation="Vertical"> <ContentPresenter x:Name="defaultRowContentContentPresenter" ContentTemplate="{Binding View.DefaultDataRowTemplate}" Content="{Binding}" /> <Border HorizontalAlignment="Stretch" VerticalAlignment="Center" BorderThickness="0 1 0 0" BorderBrush="#ffc3cedc" Padding="2"> <ProgressBar Height="5" Minimum="0" Maximum="100" Value="{Binding Row.Progress}" /> </Border> </StackPanel> </dx:MeasurePixelSnapper> </HierarchicalDataTemplate> <ControlTemplate x:Key="StateComboBoxControlTemplateKey"> <StackPanel Orientation="Horizontal" Margin="3 0 0 0" Background="Transparent"> <dx:PixelSnapper> <Image Height="16" Width="16" Source="{Binding Path=(dxe:BaseEdit.OwnerEdit).SelectedItem.ImageSource}" /> </dx:PixelSnapper> <TextBlock VerticalAlignment="Center" Margin="2" Text="{Binding Path=(dxe:BaseEdit.OwnerEdit).SelectedItem.Text}" /> </StackPanel> </ControlTemplate> <DataTemplate DataType="{x:Type local:Task}"> <StackPanel Orientation="Vertical"> <dx:MeasurePixelSnapper> <ContentPresenter x:Name="defaultRowContentContentPresenter" ContentTemplate="{Binding View.DefaultDataRowTemplate}" Content="{Binding}" /> </dx:MeasurePixelSnapper> <Border HorizontalAlignment="Stretch" VerticalAlignment="Center" BorderThickness="0 1 0 0" BorderBrush="#ffc3cedc" Padding="2"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <StackPanel Grid.Row="0" Grid.Column="0" Margin="2 0" Orientation="Horizontal"> <TextBlock FontWeight="Bold" Text="StartDate :" /> <TextBlock Margin="3 0 0 0" Text="{Binding Row.StartDate, StringFormat='MM/dd/yyyy'}" /> </StackPanel> <StackPanel Grid.Row="1" Grid.Column="0" Margin="2 0" Orientation="Horizontal"> <TextBlock FontWeight="Bold" Text="EndDate :" /> <TextBlock Margin="3 0 0 0" Text="{Binding Row.EndDate, StringFormat='MM/dd/yyyy'}" /> </StackPanel> <dxe:ComboBoxEdit Grid.Column="1" Grid.RowSpan="2" HorizontalAlignment="Right" VerticalAlignment="Center" MinWidth="100" Foreground="Black" IsTextEditable="False" ItemsSource="{Binding DataSource, Source={StaticResource StateListKey}}" DisplayTemplate="{StaticResource StateComboBoxControlTemplateKey}" EditNonEditableTemplate="{StaticResource StateComboBoxControlTemplateKey}" SelectedItem="{Binding Row.State, Mode=TwoWay}"> <dxe:ComboBoxEdit.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <dx:MeasurePixelSnapper SnapperType="Around"> <Image Width="16" Height="16" Source="{Binding ImageSource}" /> </dx:MeasurePixelSnapper> <TextBlock Margin="2" Text="{Binding Text}" /> </StackPanel> </DataTemplate> </dxe:ComboBoxEdit.ItemTemplate> </dxe:ComboBoxEdit> </Grid> </Border> </StackPanel> </DataTemplate> </ResourceDictionary> </Window.Resources> <Grid> <dxg:TreeListControl x:Name="treeListControl" DataContext="{StaticResource ViewModelKey}" ItemsSource="{Binding ProjectObjectCollection}"> <dxg:TreeListControl.Columns> <dxg:TreeListColumn FieldName="Name" AllowSorting="True" /> <dxg:TreeListColumn FieldName="Executor" AllowSorting="True" /> </dxg:TreeListControl.Columns> <dxg:TreeListControl.View> <dxg:TreeListView x:Name="treeListView" TreeDerivationMode="HierarchicalDataTemplate" AllowEditing="True" NavigationStyle="Cell" /> </dxg:TreeListControl.View> </dxg:TreeListControl> </Grid> </Window> |
▶ MainWindow.xaml.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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |