Say I have a viewmodel like this:
public class EmployeeViewModel
{
private EmployeeModel _model;
public Color BackgroundColor { get; set; }
public Name
{
get { return _model.Name; }
set
{
_model.Name = value;
NotifyPropertyChanged(Name);
}
}
}
So this viewmodel binds to a view that displays an employee. The thing to think about is, does this viewmodel represent an employee, or a "displayable" employee. The viewmodel contains some things that are view specific, for instance the background color. There can be many employees, but only one employee view.
With this in mind, when changing the displayed employee, does it make sense to create a new EmployeeViewModel and rebind to the view, or simply swap out the EmployeeModel. Is the distinction even important, or is it a matter of style?
I've always leaned toward creating new viewmodels, but I am working on a project where the viewmodels are created once and the models are swapped out. I'm not sure how I feel about this, though it seems to work fine.
NotifyPropertyChanged
get triggered?