我想到了在给ObservableCollection<T>集合加载数据时 ,使用后台线程加载,但是发现数据无法在界面上显示。
ViewModel public DeptListViewModel() { Thread thread = new Thread(LoadData); thread.IsBackground = true; thread.Start(); } private void LoadData(object obj) { db = new PlumsystemEntities(); var list = from d in db.Dept select d; Depts = new ObservableCollection<Dept>(list); }
public ObservableCollection<Dept> Depts { get; set; } private ObservableCollection<Dept> list2; public ObservableCollection<Dept> List2 { get { return list2; } set { list2 = value; RaisePropertyChanged("List2"); } }
用下边这中集合去通知。
哦,原来要这样声明集合啊。
@WaitingEver: yes.