private async void LoadDataAsync(object sender, RoutedEventArgs e) { vm.LoadCourses(await AAOAPI.RequestInfomation("学生课程表")); BindingOperations.SetBinding(comboBox1, ComboBox.SelectedIndexProperty, new Binding() { Source = vm, Path = new PropertyPath("Week"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); for (var cno = 1; cno <= 6; ++cno) { for (var weekday = 1; weekday <= 7; ++weekday) { var text = new TextBlock() { Foreground = new SolidColorBrush(Colors.White), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; Grid.SetColumn(text, weekday); Grid.SetRow(text, cno); CoursesContainer.Children.Add(text); BindingOperations.SetBinding(text, TextBlock.TextProperty, new Binding() { Source = vm[weekday - 1][cno - 1], Path = new PropertyPath("Text"), Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); } } }
private async void LoadDataAsync(object sender, RoutedEventArgs e) { vm.LoadGrades(await AAOAPI.RequestInfomation("学生成绩查询")); int row = 1, col; vm.Grades.Select(grade => grade.Serialize()).ForEach((list) => { col = 0; list.ForEach((prop) => { var block = new TextBlock() { Text = prop, Foreground = new SolidColorBrush(Colors.White), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; Grid.SetColumn(block, col++); Grid.SetRow(block, row); gradesContainer.Children.Add(block); }); ++row; }); }