Created
March 10, 2014 12:00
-
-
Save gregorybmclub/2dce50cb5272def4e2a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackPanel Orientation="Horizontal" Grid.ColumnSpan="7" Grid.Row="2"> | |
<Label Content="Search Student:" Name="lblsearchStudnet" Foreground="#FF252525"/> | |
<TextBox Height="23" Name="txtSearchSN" Width="100" | |
Text="{Binding NameSearch, UpdateSourceTrigger=PropertyChanged}"/> | |
</StackPanel> | |
<StackPanel Orientation="Horizontal" Grid.ColumnSpan="7" Grid.Row="3"> | |
<Label Content="Search by Parental name:"/> | |
<TextBox Height="23" Name="txtContactName" Width="100" | |
Text="{Binding ContactNameSearch, UpdateSourceTrigger=PropertyChanged}"/> | |
</StackPanel> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ListView Height="350" Width="690" Grid.Row="5" Name="lsNames" VerticalAlignment="Top" HorizontalAlignment="Center" | |
ScrollViewer.VerticalScrollBarVisibility="Visible" | |
ScrollViewer.HorizontalScrollBarVisibility="Visible" | |
SelectedItem="{Binding SelectedStudent}" | |
ItemsSource="{Binding StudentList}"> | |
<ListView.View> | |
<GridView> | |
<GridViewColumn CellTemplate="{StaticResource RowButtons}"/> | |
<!-- Rows of info are here --> | |
<GridViewColumn Header="Student Unique ID" DisplayMemberBinding="{Binding UniqueID}" /> | |
</GridView> | |
</ListView.View> | |
</ListView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StudentListViewModel : ViewModelBase | |
{ | |
public StudentListViewModel() | |
{ | |
StudentList = new ObservableCollection<StudentViewModel>(GetStudents()); | |
CollectionViewSource.GetDefaultView(StudentList).Filter = new Predicate<object>(MainFilter); | |
} | |
private static StudentListViewModel instance = null; | |
public static StudentListViewModel Instance() | |
{ | |
if (instance == null) | |
instance = new StudentListViewModel(); | |
return instance; | |
} | |
private StudentViewModel selectedStudent = null; | |
public StudentViewModel SelectedStudent | |
{ | |
get { return selectedStudent; } | |
set | |
{ | |
selectedStudent = value; | |
OnPropertyChanged("SelectedStudent"); | |
} | |
} | |
private ObservableCollection<StudentViewModel> studentList; | |
public ObservableCollection<StudentViewModel> StudentList | |
{ | |
get { return studentList; } | |
set | |
{ | |
studentList = value; | |
OnPropertyChanged("StudentList"); | |
} | |
} | |
internal ObservableCollection<StudentViewModel> GetStudents() | |
{ | |
if (studentList == null) | |
studentList = new ObservableCollection<StudentViewModel>(); | |
studentList.Clear(); | |
foreach (DataObjects.Student i in new StudentRepository().GetAll()) | |
{ | |
StudentViewModel c = new StudentViewModel(i); | |
studentList.Add(c); | |
} | |
return studentList; | |
} | |
//This works fine with no problem | |
private string _NameSearch; | |
public string NameSearch | |
{ | |
get { return _NameSearch; } | |
set | |
{ | |
_NameSearch = value; | |
CollectionViewSource.GetDefaultView(StudentList).Refresh(); | |
OnPropertyChanged("NameSearch"); | |
} | |
} | |
private bool FilterNameSearch(object obj) | |
{ | |
StudentViewModel item = obj as StudentViewModel; | |
if (item == null) return false; | |
if (String.IsNullOrWhiteSpace(NameSearch)) return true; | |
if (item.Firstname.ToLower().Contains(NameSearch.ToLower())) return true; | |
if (item.Surname.ToLower().Contains(NameSearch.ToLower())) return true; | |
return false; | |
} | |
private string contactNameSearch; | |
public string ContactNameSearch | |
{ | |
get { return contactNameSearch; } | |
set | |
{ | |
contactNameSearch = value; | |
CollectionViewSource.GetDefaultView(StudentList).Refresh(); | |
OnPropertyChanged("ContactNameSearch"); | |
} | |
} | |
private bool FilterContactNameSearch(object obj) | |
{ | |
StudentContactViewModel item = obj as StudentContactViewModel; | |
if (item == null) return false; | |
if (String.IsNullOrWhiteSpace(ContactNameSearch)) return true; | |
if (ContactNameSearch.Trim().Length == 0) return true; | |
if (item.Name1.ToLower().Contains(ContactNameSearch.ToLower())) return true; | |
return false; | |
} | |
public bool MainFilter(object o) | |
{ | |
return FilterSchoolSearch(o) & FilterContactNameSearch(o) & FilterNameSearch(o) & FilterFormSearch(o) & FilterIDSearch(o) | |
& FilterEnrollment(o) & FilterNameSearch(o); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment