public Student() { ResetGpaCommand = new Command(() => GradePointAverage = 2.5); MoveToTopCommand = new Command(() => StudentBody.MoveStudentToTop(this)); MoveToBottomCommand = new Command(() => StudentBody.MoveStudentToBottom(this)); RemoveCommand = new Command(() => StudentBody.RemoveStudent(this)); }
public SchoolViewModel(IDictionary <string, object> properties) { // Avoid problems with a null or empty collection. StudentBody = new StudentBody(); StudentBody.Students.Add(new Student()); string uri = "http://xamarin.github.io/xamarin-forms-book-samples" + "/SchoolOfFineArt/students.xml"; HttpWebRequest request = WebRequest.CreateHttp(uri); request.BeginGetResponse((arg) => { // Deserialize XML file. Stream stream = request.EndGetResponse(arg).GetResponseStream(); StreamReader reader = new StreamReader(stream); XmlSerializer xml = new XmlSerializer(typeof(StudentBody)); StudentBody = xml.Deserialize(reader) as StudentBody; // Enumerate through all the students foreach (Student student in StudentBody.Students) { // Set StudentBody property in each Student object. student.StudentBody = StudentBody; // Load possible Notes from properties dictionary // (for program in Chapter 25). if (properties != null && properties.ContainsKey(student.FullName)) { student.Notes = (string)properties[student.FullName]; } } }, null); // Adjust GradePointAverage randomly. Device.StartTimer(TimeSpan.FromSeconds(0.1), () => { if (studentBody != null) { int index = rand.Next(studentBody.Students.Count); Student student = studentBody.Students[index]; double factor = 1 + (rand.NextDouble() - 0.5) / 5; student.GradePointAverage = Math.Round( Math.Max(0, Math.Min(5, factor * student.GradePointAverage)), 2); } return(true); }); }
public SchoolViewModel(IDictionary <string, object> properties) { StudentBody = new StudentBody(); StudentBody.Students.Add(new Student()); string uri = "http://xamarin.github.io/xamarin-forms-book-samples/SchoolOfFineArt/students.xml"; HttpWebRequest request = WebRequest.CreateHttp(uri); request.BeginGetResponse((arg) => { Stream stream = request.EndGetResponse(arg).GetResponseStream(); StreamReader reader = new StreamReader(stream); XmlSerializer xml = new XmlSerializer(typeof(StudentBody)); StudentBody = xml.Deserialize(reader) as StudentBody; foreach (Student student in StudentBody.Students) { student.StudentBody = StudentBody; if (properties != null && properties.ContainsKey(student.FullName)) { student.Notes = (string)properties[student.FullName]; } } }, null); Device.StartTimer(TimeSpan.FromSeconds(0.1), () => { if (studentBody != null) { int index = rand.Next(studentBody.Students.Count); Student student = StudentBody.Students[index]; double factor = 1 + (rand.NextDouble() - 0.5) / 5; student.GradePointAverage = Math.Round(Math.Max(0, Math.Min(5, factor * student.GradePointAverage)), 2); } return(true); }); }