I am building an wpf app using MVVM. I have viewModels the employ lazy loading like below:
public class AssignmentsViewModel
{
List<AssignmentViewModel> _Assignments;
public List<AssignmentViewModel> Assignments
{
get
{
if (_Assignments == null)
_Assignments = new List<AssignmentViewModel>(Data.GetAssignments());
return _Assignments;
}
set { _Assignments = value; }
}
}
public class AssignmentViewModel
{
List<NoteViewModel> _Notes;
public List<NoteViewModel> Notes
{
get
{
if (_Notes == null)
_Notes = new List<NoteViewModel>(Data.GetNotes());
return _Notes;
}
set { _Notes = value; }
}
}
The View has the AssignmentViewModels in a ListView and the Notes in a ListBox with a datatemplate.
When I display one of the AssignmentViewModels that has 160 items it takes 1000 ms to load. I thought it was because of the Notes property grabbing from a database table with 1.5million rows. I checked it and it only took 60ms to populate the Notes list. So I'm guessing that it's the databinding of loading the 160 items into the listbox. But that shouldn't be the case because listBoxes virtualize their content(I Snooped it and verified that the items are in a Virtualizing stackpanel).
So I'm at a loss, I don't know how to find out what is taking the extra 940 ms.
What can I do to track this down? Performance is key, and I don't know how to improve it.