Binding works without INotifyPropertyChanged, why?
Is it a bad practice to bind my UI to HTTP API model directly without creating a separate view model?
The only disadvantage is it won't implement INotifyPropertyChanged
so UI won't update when you change the property from your code - but what if you don't need to update your property from your code?
This is my API response model:
public class EventResponseModel
{
public int Id { get; set; }
public string Subject { get; set; }
public string Description { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string ArgbColor { get; set; } // should bind to Brush
public Location Location { get; set; }
public IEnumerable<Person> Attendees { get; set; }
}
In the model above I have ArgbColor
that need to be bound to Brush
in XAML. I could probably create StringToBrushConverter : IValueConverter
to make it work instead of creating a separate view model.
Is this always preferred to create a separate view model, map to it and then bind to it?
For editing, I would still have a separate VM and use a composition like:
public class EventVM
{
public EventResponseModel EditedEvent { get; set; }
// available locations etc., commands for saving
}