View Models
What is a View Model?
View Models contain the data and logic that accompanies our UI, separating view logic and model logic keeps our UIs more organised and promotes better coding.
Why are View Models needed?
The simplest reason is to keep different things in different places.
Examples of View Model data and logic
Notice how none of the properties or methods relate to the UI and focus entirely on Data and back end.
// Data internal ObservableCollection<User> Users { get; } // Methods internal void LoadSettings(); internal void ResetSettings(); internal void AddUser(User user);
Examples of view data and logic
Notice that the properties and methods are very much view specific only relating to the UI.
// Data private bool IsButtonVisible { get; } private static float BorderThickness { get; } public Color BackgroundColour { get; } // Methods internal void RedrawView(); internal void CloseView();