private void StudentSearch_TextChanged(object sender, TextChangedEventArgs e) { if ((e.OldTextValue ?? "").Length > (e.NewTextValue ?? "").Length) { InGrade = Attendance.StudentsOfGrade(ClassName); InitializeTeachers(); InitializeStudents(); } else { NamesTable = new TableSection(); List <ViewCell> visible = new List <ViewCell>(); string filter = StudentSearch.Text.Trim().ToLower(); int count = 0; foreach (ViewCell c in Backup) { StackLayout s = c.View as StackLayout; Label l = s.Children[2] as Label; if (l.Text.ToLower().Contains(filter)) { // make visible s.Children[1] = GetPhoto(new KeyValuePair <string, string>((s.Children[0] as Label).Text, l.Text), true); visible.Add(c); count++; } } foreach (ViewCell v in visible) { NamesTable.Add(v); } if (count == 0) { // there are no students that match this filter NotFoundStack.IsVisible = true; } else { NotFoundStack.IsVisible = false; } NamesTableRoot.Clear(); NamesTableRoot.Add(NamesTable); Scroll.ScrollToAsync(0, 0, false); } }
private void InitializeTeachers() { TeachersNamesTable.Clear(); TeacherBackup.Clear(); TeachersInGrade = Attendance.TeachersOfGrade(ClassName); /* * if (TeachersInGrade.Count == 0) * { * NotFoundStack.IsVisible = true; * }*/ int count = 0; string filter = StudentSearch.Text == null ? "" : StudentSearch.Text.Trim().ToLower(); foreach (var t in TeachersInGrade) { ViewCell cell = new ViewCell() { Height = 70, }; StackLayout sl = new StackLayout() { Orientation = StackOrientation.Horizontal, BackgroundColor = Color.FromHex("#FFFFFF") }; sl.Padding = new Thickness(0, 0, 10, 0); sl.Children.Add(new Label() { Text = t.Key, IsVisible = false }); sl.Children.Add(GetPhoto(t, false)); CheckBox cb = new CheckBox() { HorizontalOptions = LayoutOptions.EndAndExpand }; Label l = new Label() { Text = t.Value, VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.Black, FontSize = 16, Padding = new Thickness(30, 0, 0, 0) }; cell.Tapped += TableCell_Tapped; sl.Children.Add(l); sl.Children.Add(cb); cell.View = sl; TeacherBackup.Add(cell); if (Attendance.TeacherAttendedToday(t.Key, DatePicker.Date)) { cb.IsChecked = true; } else { cb.IsChecked = false; } if (t.Value.ToLower().Contains(filter)) { TeachersNamesTable.Add(cell); count++; } } NamesTableRoot.Clear(); TeachersNamesTable.Add(new ViewCell() { View = new Label { BackgroundColor = Color.LightGray } }); NamesTableRoot.Add(TeachersNamesTable); }