private void InitCourseList() { #region 本地数据库时使用,数据加载一般不会有延时 //// 获取所有课程列表 //ICourseService cSvc = new CourseService(); //this.courseAll = cSvc.GetCourseTeacherInfo(); //this.CourseInfoList = new ObservableCollection<Course>(courseAll); #endregion #region 远端数据库时使用 ICourseService cSvc = new CourseService(); Task.Run(new System.Action(async() => { courseAll = cSvc.GetCourseTeacherInfo(); // 延迟4s显示 await Task.Delay(4000); // 加入主线程序列 Application.Current.Dispatcher.Invoke(new System.Action(() => { foreach (var item in courseAll) { CourseInfoList.Add(item); } })); })); #endregion }
private void DoTeacherFilterCmd(object o) { string name = o.ToString(); List <Course> tempList = this.courseAll; if (name != "全部") { tempList = this.courseAll.Where(t => t.Teacher.Exists(u => u.RealName == name)).ToList(); } CourseInfoList.Clear(); foreach (var item in tempList) { this.CourseInfoList.Add(item); } }