Class ViewModelActivator
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
ViewModelActivator is a helper class that you instantiate in your ViewModel classes in order to help with Activation. Views will internally call this class when the corresponding View comes on screen. This means you can set up resources such as subscriptions to global objects that should be cleaned up on exit. Once you instantiate this class, use the WhenActivated method to register what to do when activated.
View Activation is **not** the same as being loaded / unloaded; Views are Activated when they *enter* the Visual Tree, and are Deactivated when they *leave* the Visual Tree. This is a critical difference when it comes to views that are recycled, such as UITableViews or Virtualizing ScrollViews.
Create this class solely in the **Base Class** of any classes that inherit from this class (i.e. if you create a FooViewModel that supports activation, the instance should be protected and a child BarViewModel should use the existing ViewModelActivator).
NOTE: You **must** set up Activation in the corresponding View when using ViewModel Activation.
- Inheritance
-
View
Model Activator
- Implements
- Extension Methods
Constructors
ViewModelActivator()
Initializes a new instance of the View
Properties
Activated
Gets a observable which will tick every time the Activator is activated.
Property Value
- IObservable<Unit>
The activated.
Deactivated
Gets a observable which will tick every time the Activator is deactivated.
Property Value
- IObservable<Unit>
The deactivated.
Methods
Activate()
This method is called by the framework when the corresponding View is activated. Call this method in unit tests to simulate a ViewModel being activated.
Returns
- IDisposable
A Disposable that calls Deactivate when disposed.
Deactivate(bool)
This method is called by the framework when the corresponding View is deactivated.
Parameters
ignoreRefCount
boolForce the VM to be deactivated, even if more than one person called Activate.