Skip to content

About

A composable, cross-platform MVVM framework for .NET inspired by functional reactive programming. It moves mutable state out of the user interface, keeps each feature's logic in one readable place, and makes applications easier to test. Supports WPF, WinForms, WinUI, .NET MAUI, Avalonia, Uno Platform, Blazor and Android.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

8.6k stars

Watchers

336 watching

Forks

Repository files navigation

ReactiveUI

ReactiveUI

Build NuGet Downloads Coverage License Discussions

What is ReactiveUI?

ReactiveUI is a composable, cross-platform model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming, which is a paradigm that allows you to abstract mutable state away from your user interfaces and express the idea around a feature in one readable place and improve the testability of your application.

🔨 Get Started 🛍 Install Packages 🎞 Watch Videos 🎓 View Samples 🎤 Discuss ReactiveUI

Your first view model

A view shows data that changes, so it needs to know when a value changes. Written by hand, each property needs a field and a setter that raises a change notification. Each command needs a property that wraps a method. ReactiveUI writes that code for you while your project builds.

A source generator is a compiler add-on that writes C# code during the build. The ReactiveUI packages bring two of them. ReactiveUI.SourceGenerators writes reactive properties and commands. ReactiveUI.Binding writes the code behind WhenAnyValue, ToProperty and the view bindings. You install neither yourself.

1. Install the ReactiveUI package for your UI framework. A class library that holds only view models installs ReactiveUI.

dotnet add package ReactiveUI.WPF

2. Declare the view model as a partial class and mark its members.

using ReactiveUI;
using ReactiveUI.SourceGenerators;

public partial class LoginViewModel : ReactiveObject
{
    private readonly IObservable<bool> _canLogIn;

    public LoginViewModel()
    {
        _canLogIn = this.WhenAnyValue(
            static x => x.UserName,
            static x => x.Password,
            static (userName, password) => userName.Length > 0 && password.Length > 0);

        _isValidHelper = _canLogIn.ToProperty(this, static x => x.IsValid);
    }

    [Reactive]
    public partial string UserName { get; set; } = string.Empty;

    [Reactive]
    public partial string Password { get; set; } = string.Empty;

    [ObservableAsProperty]
    public partial bool IsValid { get; }

    [ReactiveCommand(CanExecute = nameof(_canLogIn))]
    private async Task<bool> LogInAsync(CancellationToken cancellationToken)
    {
        await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
        return Password == "secret";
    }
}

WhenAnyValue returns a stream, an IObservable<T> that emits a new value each time either property changes.

3. Build. The generators write the rest of the class:

  • The bodies of UserName and Password. Setting either one raises the change notification.
  • The body of IsValid and its _isValidHelper field. ToProperty keeps IsValid equal to the latest value of _canLogIn.
  • A LogInCommand property. It holds a command, an ICommand that also reports each result as a stream. The command runs LogInAsync, and it is enabled only while _canLogIn emits true. The generator drops the Async suffix from the name.

Next, bind the properties and the command to your view with Bind and BindCommand. The ReactiveUI.Binding documentation shows how. The source generators documentation lists every attribute and option.

Partial properties with an initial value need C# 14, the default language version for .NET 10.

How the packages fit together

ReactiveUI is a set of packages. You install the package for your UI framework, and it brings the rest.

Package What it gives you
ReactiveUI ReactiveObject, ReactiveCommand, activation, routing and schedulers, built on ReactiveUI.Primitives. It brings ReactiveUI.Core and ReactiveUI.Binding.
ReactiveUI.Reactive The same API built for System.Reactive. It brings ReactiveUI.Core and ReactiveUI.Binding.Reactive.
ReactiveUI.Core The parts both flavours share. It brings ReactiveUI.SourceGenerators.
ReactiveUI.Binding WhenAnyValue, Bind, OneWayBind, BindCommand, ToProperty, [ObservableAsProperty] and view location.
ReactiveUI.SourceGenerators [Reactive], [ReactiveCommand], [ReactiveCollection], [BindableDerivedList] and [IReactiveObject].

The ReactiveUI documentation covers the core package, and the installation guide shows which package to install for each platform.

Pick a flavour

ReactiveUI comes in two flavours with the same API. They differ only in the reactive types that appear in that API.

You want Install Reactive types in the API
No System.Reactive dependency ReactiveUI, ReactiveUI.WPF, ReactiveUI.WinForms, ReactiveUI.WinUI, ReactiveUI.Maui, ReactiveUI.Blazor, ReactiveUI.AndroidX ReactiveUI.Primitives: RxVoid, ISequencer, Signal<T>
To mix with code that uses System.Reactive ReactiveUI.Reactive, ReactiveUI.WPF.Reactive, ReactiveUI.WinForms.Reactive, ReactiveUI.WinUI.Reactive, ReactiveUI.Maui.Reactive, ReactiveUI.Blazor.Reactive, ReactiveUI.AndroidX.Reactive System.Reactive: Unit, IScheduler, Subject<T>

ReactiveUI.Primitives is ReactiveUI's own library of streams, operators and schedulers. Both flavours run on it. The default flavour does not depend on System.Reactive, so your app ships fewer assemblies.

The System.Reactive flavour puts its own types in the ReactiveUI.Reactive namespace. A file that uses ReactiveObject or ReactiveCommand from it adds using ReactiveUI.Reactive;.

Bindings come from ReactiveUI.Binding

ReactiveUI runs WhenAnyValue, Bind, OneWayBind, BindCommand, ToProperty and view location on ReactiveUI.Binding. Its source generator writes the code for each binding while your project builds. Nothing looks up a property by name at run time, so bindings are safe to trim and to publish with Native AOT.

The ReactiveUI package imports the ReactiveUI.Binding namespace into your project, so binding calls need no using. Moving from an earlier version? The migration guide covers the calls that need an Unsafe twin and the behavior that changed.

Source generators come with ReactiveUI.Core

ReactiveUI.Core references ReactiveUI.SourceGenerators and passes its generators on. Every project that installs a ReactiveUI package can use [Reactive], [ReactiveCommand] and the other attributes. Add using ReactiveUI.SourceGenerators; to each file that uses them. The generators check which flavour your project references and write code for that flavour.

  • Remove your own reference to ReactiveUI.SourceGenerators, or set it to the version ReactiveUI brings or later. An older version fails to restore with error NU1605.

Analyzers

An analyzer checks your code as you type and reports problems as warnings or errors. ReactiveUI.Binding and ReactiveUI.SourceGenerators run their analyzers in your project. They report binding calls and attributes that the generators cannot handle. Diagnostic RXUIBIND021 flags a binding call with no generated binding behind it, such as one that targets a member another source generator adds or a stored lambda; that call throws at run time, so treat the warning as a bug to fix rather than suppress.

The analyzers inside ReactiveUI.Primitives stay out of your project. ReactiveUI references ReactiveUI.Primitives with ExcludeAssets="analyzers". To use them, reference ReactiveUI.Primitives directly:

<PackageReference Include="ReactiveUI.Primitives" Version="x.y.z" />

Routing

Routing (RoutingState and IScreen) is part of the ReactiveUI package. The WPF, WinUI and MAUI packages add a RoutedViewHost control that shows the current view, and Windows Forms adds RoutedControlHost. RoutingState reports navigation as streams. CurrentViewModel emits the view model on top of the stack. NavigationStackChanged emits a read-only copy of the whole stack after each change. CanNavigateBack emits whether there is a view model to go back to. The routing migration guide covers moving from the ReactiveUI.Routing package.

Platform packages

Install the package for your UI framework. Each one brings ReactiveUI. Each one except ReactiveUI.Uno has a .Reactive twin for the System.Reactive flavour.

Platform Package NuGet
Class libraries ReactiveUI CoreBadge
WPF ReactiveUI.WPF WpfBadge
WinUI ReactiveUI.WinUI WinUiBadge
MAUI ReactiveUI.Maui MauiBadge
Windows Forms ReactiveUI.WinForms WinBadge
Android (AndroidX) ReactiveUI.AndroidX DroXBadge
Blazor ReactiveUI.Blazor BlazBadge
Avalonia ReactiveUI.Avalonia AvaBadge
Uno Platform ReactiveUI.Uno UnoBadge
Unit tests ReactiveUI.Testing TestBadge

ReactiveUI.Avalonia and ReactiveUI.Uno live in their own repositories.

ReactiveUI.Validation adds validation rules for view models. It lives in its own repository. ValBadge

Documentation

  • RxSchedulers - Using ReactiveUI schedulers without RequiresUnreferencedCode attributes

Book

There has been an excellent book written by our Alumni maintainer Kent Boogart.

Sponsors

JetBrains gives ReactiveUI's maintainers licences for its tools through its open source support programme. Anthropic supports them with Claude through Claude for Open Source. OpenAI supports them with Codex through Codex for Open Source. Snyk gives the maintainers access to security tools through its Secure Developer Program.

JetBrains Claude by Anthropic OpenAI Sponsored by Snyk

See our sponsors for more information. JetBrains, Claude, Anthropic, OpenAI and Codex names and logos are trademarks of their respective owners. Snyk and the Snyk logo are trademarks of Snyk Ltd.

Migration from Xamarin and .NET 8 MAUI

Xamarin Users

As of May 2024, Microsoft ended support for Xamarin per their support policy. ReactiveUI has removed support for legacy Xamarin platforms in favor of modern .NET MAUI. For Xamarin projects:

  • Xamarin.Forms → Migrate to MAUI and use ReactiveUI.Maui
  • Xamarin.Android → Migrate to MAUI Android or use ReactiveUI.AndroidX for native Android
  • Xamarin.iOS/Mac → Migrate to MAUI iOS/Mac Catalyst

For guidance on migrating from Xamarin to MAUI, see the official migration documentation.

MAUI Users

ReactiveUI supports .NET 10 and .NET 11 for MAUI platforms:

  • net10.0-android / net11.0-android
  • net10.0-ios / net11.0-ios
  • net10.0-maccatalyst / net11.0-maccatalyst
  • net10.0-windows10.0.19041.0 / net11.0-windows10.0.19041.0

Examples

Platform-specific sample applications are included in src/examples/:

Sample Platform Description
ReactiveUI.Samples.Wpf WPF Login form with reactive bindings, PasswordBox event marshaling
ReactiveUI.Samples.Winforms WinForms Login form with IViewFor, programmatic UI layout
ReactiveUI.Samples.Maui MAUI Cross-platform login with Shell navigation, ReactiveContentPage
ReactiveUI.Builder.WpfApp WPF Multi-instance chat app with routing, suspension, and network sync
ReactiveUI.Builder.BlazorServer Blazor Server Chat app with server-side Blazor and reactive components

All samples target .NET 10, use RxAppBuilder for initialization, and demonstrate WhenActivated, Bind/ BindCommand, and proper subscription disposal.

This is how we use the donations:

  • Allow the core team to work on ReactiveUI
  • Thank contributors if they invested a large amount of time in contributing
  • Support projects in the ecosystem

Contribute

ReactiveUI is part of ReactiveUI and is released under the MIT license. We welcome contributions of every size, from bug reports and documentation to features and tests.

Coding standards

Every pull request must meet these standards. The build checks most of them.

  • Follow the ReactiveUI C# style guide.
  • The repository's .editorconfig and the StyleSharp, PerformanceSharp and SecuritySharp analyzers run on every build. Fix each finding in the code. Do not suppress it or relax the .editorconfig.
  • Add tests for every bug fix and new feature.
  • Document public APIs with XML documentation comments.
  • Write commit messages in the Conventional Commits format.
  • Follow the Code of Conduct.

Support the project

Core Team


Glenn Watson

Melbourne, Australia


Chris Pulman

United Kingdom

Alumni Core Team

The following have been core team members in the past.


Geoffrey Huntley

Sydney, Australia


Kent Boogaart

Brisbane, Australia


Olly Levett

London, United Kingdom


Anaïs Betts

San Francisco, USA


Brendan Forster

Melbourne, Australia


Claire Novotny

New York, USA


Artyom Gorchakov

Moscow, Russia


Rodney Littles II

Texas, USA


Colt Bauman

South Korea

.NET Foundation

ReactiveUI is part of the .NET Foundation. Other projects that are associated with the foundation include the Microsoft .NET Compiler Platform ("Roslyn") as well as the Microsoft ASP.NET family of projects, and Microsoft .NET Core.

About

A composable, cross-platform MVVM framework for .NET inspired by functional reactive programming. It moves mutable state out of the user interface, keeps each feature's logic in one readable place, and makes applications easier to test. Supports WPF, WinForms, WinUI, .NET MAUI, Avalonia, Uno Platform, Blazor and Android.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

8.6k stars

Watchers

336 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages