Windows Forms¶
ReactiveUI.WinForms connects ReactiveUI to Windows Forms. Add it by following
Installation. ReactiveUI.WinForms also ships as
ReactiveUI.WinForms.Reactive, built from the same source, for an app that uses System.Reactive. See
Windows Forms for a full walkthrough, built around a library loans desk.
Guidelines¶
- View models inherit from
ReactiveObject. - Use
IActivatableViewModelandWhenActivatedfor lifecycle. See When Activated. - Keep every subscription disposed. See Cleaning up subscriptions and Disposables.
- Convert WinForms events to streams instead of attaching event handlers. The extension methods in
ReactiveUI.Primitives.ObservableEventsturn an event into anIObservable<T>; see Events and ObservableEvents. - A control that needs a view model derives from
ReactiveUserControl<TViewModel>, aUserControlthat implementsIViewFor<TViewModel>. - Host a routed page stack with
RoutedControlHost, and a single view model withViewModelControlHost. Neither needs a hand-writtenswitchover the current page or view model.