-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainViewModel.cs
51 lines (47 loc) · 1.76 KB
/
MainViewModel.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
using DevExpress.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MultiLevelMasterDetail {
public class MainViewModel : ViewModelBase {
public MainViewModel() {
Items = new ObservableCollection<MasterLevelItem>();
InitMasterItems();
CurrentMasterItem = null;
}
public ObservableCollection<MasterLevelItem> Items { get; private set; }
public MasterLevelItem CurrentMasterItem { get { return GetValue<MasterLevelItem>(); } set { SetValue(value); } }
public DetailLevelItem CurrentDetailItem { get { return GetValue<DetailLevelItem>(); } set { SetValue(value); } }
void InitMasterItems() {
for(int i = 0; i < 10; i++) {
Items.Add(new MasterLevelItem() {
MasterId = i,
MasterName = String.Format("master item {0}", i),
});
}
}
}
public class MasterLevelItem {
public int MasterId { get; set; }
public string MasterName { get; set; }
public List<DetailLevelItem> DetailItems { get; set; }
public MasterLevelItem() {
DetailItems = new List<DetailLevelItem>();
InitDetailItems();
}
void InitDetailItems() {
for(int i = 0; i < 10; i++) {
DetailItems.Add(new DetailLevelItem() {
DetailId = i,
DetailName = String.Format("detail item {0}", i),
MasterItem = this,
});
}
}
}
public class DetailLevelItem {
public int DetailId { get; set; }
public string DetailName { get; set; }
public object MasterItem { get; set; }
}
}