我将会把代码中的SelectedSchoolList这个可观察集合赋值的函数每分钟调用一次。我希望在这个可观察集合中有任何数据发生变化时,能够调用另一个函数(比如CallIfValueChanged();)。请问我该怎么实现?
我的代码:
我的代码:
public static ObservableCollection<SelectedSchoolList> _SelectedSchoolList = new ObservableCollection<SelectedSchoolList>();
DispatcherTimer dispatcherTimer;
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
// callback runs on UI thread
async void dispatcherTimer_Tick(object sender, object e)
{
response_from_server = await CallWebService();
if (!response_from_server.Equals("FAIL", StringComparison.CurrentCultureIgnoreCase))
{
parseJSONandAssignValuesToSelectedSchoolList (response_from_server);//this function assigns values to _SelectedSchoolList
}
}
CallIfValueChanged();// I want to call this function here only if any data on '_SelectedSchoolList' is updated/changed
我的课程:
class SelectedSchoolList : INotifyPropertyChanged
{
public string SchoolName { get; set; }
public string Score { get; set; }
public ObservableCollection<SelectedStudentList> SelectedStudentArray { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
public class SelectedStudentList
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public string IndividualScore { get; set; }
}