Class ViewModel
- Namespace
- BSGameLib.UI
- Assembly
- BSGameLib.UI.dll
The base of a view-model that builds its own view, in BuildView(IViewBuilder).
public abstract class ViewModel : ViewModelBase, IViewModel, IDataContext, INotifyPropertyChanged
- Inheritance
-
ViewModel
- Implements
- Derived
- Inherited Members
Constructors
ViewModel(IViewManager)
Creates a view-model that shows its views through viewManager.
public ViewModel(IViewManager viewManager)
Parameters
viewManagerIViewManager
Properties
ViewManager
The view manager, for showing other views from this view-model.
protected IViewManager ViewManager { get; }
Property Value
Methods
BuildView(IViewBuilder)
Describes the view with builder. Called each time the view is built. The
default describes nothing.
protected virtual void BuildView(IViewBuilder builder)
Parameters
builderIViewBuilder
OnViewCreating()
Runs each time this view model's view is built, before the new view exists.
protected virtual void OnViewCreating()
Remarks
View models are registered as singletons, so the same instance is reused every time a screen is shown -- but its view is rebuilt from scratch each time. Anything a view model remembers about the previous view is therefore stale on arrival, and worse than stale if it is a "already did this" flag: the work it guards will not be redone against controls that no longer exist.
Odyssey's Create Character screen is the worked example. It kept the typed name and a flag saying its class dropdown had been filled in; on a second visit the name was still the last one used, and the dropdown -- a brand new, empty control -- was never populated, because the flag still said it had been.
Override to put per-visit state back to how a fresh screen should look. Nothing that touches controls belongs here; the view does not exist yet.