I have a ListView that I set it's ItemsSource to list all the Assignments (a table in my SQL Database, ORM is LINQ to SQL) like so:
ltvAssignments.ItemsSource = _repo.ListAssignments();
(This bit of code is exactly after InitializeCompenent() is called) And for the heck of it, I added a sample:
Assignment sample1 = new Assignment()
{
Title = "A Test",
Start = DateTime.Now,
Due = DateTime.Now,
Kind = (byte) Kind.Assignment,
Priority = (byte) Priority.Medium,
};
_repo.CreateAssignment(sample1);
_repo.SaveChanges();
(where _repo is my Repository because I am using the repository pattern) When I put this bit of code before I set the ListView's ItemsSource, the sample shows. BUT when this bit of code is anywhere after ItemsSource is set, the sample doesn't show. How can I constantly update the ItemsSource everytime an Assignment is added?
My IRepository:
public interface IAssignmentRepository
{
Assignment CreateAssignment(Assignment assignmentToCreate);
void DeleteAssignment(Assignment assignmentToDelete);
Assignment GetAssignment(int id);
IEnumerable<Assignment> ListAssignments();
void SaveChanges();
}