Reactive validation for ReactiveUI view models. Declare validation rules as observables over properties and bind the results to views on any supported .NET platform.
Repo reactiveui/ReactiveUI.Validation, read from GitHub 10 h ago. reactiveui has not joined Take My Repo.
reactiveui/ReactiveUI.Validation is a public repo on GitHub by reactiveui. Reactive validation for ReactiveUI view models. Declare validation rules as observables over properties and bind the results to views on any supported .NET platform. It declares the MIT license on GitHub. It is written mainly in C#, has 273 stars and last changed on 2026-11-22. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Validation for ReactiveUI based solutions, functioning in a reactive way.
Read this in other languages: Español.
Chris Pulman London, UK |
Glenn Watson Melbourne, Australia |
ReactiveUI.Validation was originally developed by @jcmm33 as Vistian.Reactive.Validation, and then refactored and updated by Àlex Martínez Morón and the ReactiveUI community.
| Platform | Targets |
|---|---|
| .NET | net10.0, net11.0 |
| .NET Framework | net47, net471, net472, net48, net481 |
| Windows | net10.0-windows10.0.19041.0, net11.0-windows10.0.19041.0 |
| Android (MAUI) | net10.0-android, net11.0-android |
Install the following package into your class library and into a platform-specific project.
| Platform | Package | NuGet |
|---|---|---|
| Any Platform | ReactiveUI.Validation | |
| AndroidX (MAUI) | ReactiveUI.Validation.AndroidX | |
Any Platform, with ReactiveUI.Reactive |
ReactiveUI.Validation.Reactive | |
AndroidX (MAUI), with ReactiveUI.Reactive |
ReactiveUI.Validation.AndroidX.Reactive |
Pick the package that matches your ReactiveUI package:
ReactiveUI, install ReactiveUI.Validation.ReactiveUI.Reactive (the System.Reactive flavour), install ReactiveUI.Validation.Reactive. On AndroidX, install ReactiveUI.Validation.AndroidX.Reactive as well.ReactiveUI.Validation.Reactive has the same API. Its namespaces start with ReactiveUI.Validation.Reactive instead of ReactiveUI.Validation. Its schedulers are System.Reactive IScheduler instances.
IValidatableViewModel.ValidationRule extension methods.BindValidation or INotifyDataErrorInfo.IValidatableViewModel, which has a single member, ValidationContext. The ValidationContext contains all of the functionality surrounding the validation of the ViewModel. Most access to the specification of validation rules is performed through extension methods on the IValidatableViewModel interface. Then, add validation to the ViewModel.using ReactiveUI.Validation.Extensions;
public class SampleViewModel : ReactiveObject, IValidatableViewModel
{
public SampleViewModel()
{
// Creates the validation for the Name property.
this.ValidationRule(
viewModel => viewModel.Name,
name => !string.IsNullOrWhiteSpace(name),
"You must specify a valid name");
}
public ValidationContext ValidationContext { get; } = new ValidationContext();
private string _name;
public string Name
{
get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value);
}
}
For more complex validation scenarios there are several more overloads of the ValidationRule extension method that accept observables. These allow validation to occur asynchronously, and allows complex chains of observables to be combined to produce validation results.
The simplest accepts an IObservable<bool> where the observed boolean indicates whether the ValidationRule is valid or not. The overload accepts a message which is used when the observable produces a false (invalid) result.
IObservable<bool> passwordsObservable =
this.WhenAnyValue(
x => x.Password,
x => x.ConfirmPassword,
(password, confirmation) => password == confirmation);
this.ValidationRule(
vm => vm.ConfirmPassword,
passwordsObservable,
"Passwords must match.");
Any existing observables can be used to drive a ValidationRule using the extension method overload that accepts an arbitrary IObservable<TState> streams of events. The overload accepts a custom validation function that is supplied with the latest TState, and a custom error message function, responsible for formatting the latest TState object. The syntax for this looks as follows:
// IObservable<{ Password, Confirmation }>
var passwordsObservable =
this.WhenAnyValue(
x => x.Password,
x => x.ConfirmPassword,
(password, confirmation) =>
new { Password = password, Confirmation = confirmation });
this.ValidationRule(
vm => vm.ConfirmPassword,
passwordsObservable,
state => state.Password == state.Confirmation,
state => $"Passwords must match: {state.Password} != {state.Confirmation}");
Note The function to extract a message (
messageFunc) is only invoked if the function to establish validity (isValidFunc) returnsfalse, otherwise the message is set tostring.Empty.
Finally, you can directly supply an observable that streams any object (or struct) that implements IValidationState; or you can use the ValidationState base class which already implements the interface. As the resulting object is stored directly against the context without further transformation, this can be the most performant approach:
IObservable<IValidationState> usernameNotEmpty =
this.WhenAnyValue(x => x.UserName)
.Select(name => string.IsNullOrEmpty(name)
? new ValidationState(false, "The username must not be empty")
: ValidationState.Valid);
this.ValidationRule(vm => vm.UserName, usernameNotEmpty);
Note As a valid
ValidationStatedoes not really require a message, there is a singletonValidationState.Validproperty that you are encouraged to use to indicate a valid state whenever possible, to reduce memory allocations.
using ReactiveUI.Validation.Extensions;
public class SampleView : ReactiveContentPage<SampleViewModel>
{
public SampleView()
{
InitializeComponent();
this.WhenActivated(disposables =>
{
this.Bind(ViewModel, vm => vm.Name, view => view.Name.Text)
.DisposeWith(disposables);
// Bind any validations that reference the Name property
// to the text of the NameError UI control.
this.BindValidation(ViewModel, vm => vm.Name, view => view.NameError.Text)
.DisposeWith(disposables);
// Bind any validations attached to this particular view model
// to the text of the FormErrors UI control.
this.BindValidation(ViewModel, view => view.FormErrors.Text)
.DisposeWith(disposables);
});
}
}
There are extensions methods for Android and its Material design control TextInputLayout. These extensions use internally the Error property from the TextInputLayout control, allowing you to implement a fully native behavior to showing validation errors. To use these extensions you must import ReactiveUI.Validation.Extensions and install ReactiveUI.Validation.AndroidX:
dotnet add package ReactiveUI.Validation.AndroidX
// This using directive makes Android-specific extensions available.
using ReactiveUI.Validation.Extensions;
public class SignUpActivity : ReactiveAppCompatActivity<SignUpViewModel>
{
// The Android native text boxes declared in an .axml file.
public TextInputEditText Password { get; set; }
public TextInputEditText ConfirmPassword { get; set; }
// The layouts wrapping the text boxes declared in an .axml file.
public TextInputLayout PasswordField { get; set; }
public TextInputLayout ConfirmPasswordField { get; set; }
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
// The WireUpControls method is a magic ReactiveUI utility method for Android, see:
// https://www.reactiveui.net/docs/handbook/data-binding/xamarin-android/wire-up-controls
this.WireUpControls();
this.Bind(ViewModel, x => x.Password, x => x.Password.Text);
this.Bind(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPassword.Text);
// Bind any validations which reference the Password property
// to the Error property of the TextInputLayout control.
this.BindValidation(ViewModel, x => x.Password, PasswordField);
this.BindValidation(ViewModel, x => x.ConfirmPassword, ConfirmPasswordField);
}
}
INotifyDataErrorInfo SupportFor those platforms that support the INotifyDataErrorInfo interface, ReactiveUI.Validation provides a helper base class named ReactiveValidationObject. The helper class implements both the IValidatableViewModel interface and the INotifyDataErrorInfo interface. It listens to any changes in the ValidationContext and invokes INotifyDataErrorInfo events.
using ReactiveUI.Validation.Extensions;
public class SampleViewModel : ReactiveValidationObject
{
public SampleViewModel()
{
this.ValidationRule(
viewModel => viewModel.Name,
name => !string.IsNullOrWhiteSpace(name),
"Name shouldn't be null or white space.");
}
private string _name = string.Empty;
public string Name
{
get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value);
}
}
Note Keep in mind that
INotifyDataErrorInfois only supported via XAML binding. ReactiveUI binding doesn't use the inbuilt classes of WPF.
When using a ValidationRule overload that accepts an observable, please remember to supply the property which the validation rule is targeting as the first argument. Otherwise it is not possible for INotifyDataErrorInfo to conclude which property the error message is for.
this.ValidationRule(
vm => vm.ConfirmPassword,
passwordsObservable,
"Passwords must match.");
You can pass an instance of IValidationTextFormatter<T> to a call to BindValidation if you'd like to override the default SingleLineFormatter used in the validation library. The SingleLineFormatter accepts a separator char and uses whitespace by default, so the code snippet below shows how to use a non-default separator char:
// This formatter is based on the default SingleLineFormatter but uses a custom separator char.
var formatter = new SingleLineFormatter(Environment.NewLine);
this.BindValidation(ViewModel, x => x.ErrorLabel.Text, formatter)
.DisposeWith(disposables);
The simplest possible custom IValidationTextFormatter<TOut> implementation may look like this one.
private class ConstFormatter : IValidationTextFormatter<string>
{
private readonly string _text;
public ConstFormatter(string text = "The input is invalid.") => _text = text;
public string Format(ValidationText validationText) => _text;
}
// This formatter is based on a custom IValidationTextFormatter implementation.
var formatter = new ConstFormatter("The input is invalid.");
this.BindValidation(ViewModel, x => x.ErrorLabel.Text, formatter)
.DisposeWith(disposables);
If you'd like to override the IValidationTextFormatter<string> used in ReactiveUI.Validation by default, register an instance of IValidationTextFormatter<string> into Locator.CurrentMutable before your app starts. This could be useful in cases when your app needs localization and you wish to pass message keys instead of messages to ValidationRule calls.
// Register a singleton instance of IValidationTextFormatter<string> into Splat.Locator.
Locator.CurrentMutable.RegisterConstant(new CustomFormatter(), typeof(IValidationTextFormatter<string>));
In essence, ReactiveUI.Validation is a relatively simple model of the ValidationContext containing a list of IValidationComponent instances. An IValidationComponent provides an observable of IValidationState. Whenever validation state changes (either a transition of validity) or ValidationText changes, then a new value is pushed out.
ReactiveUI.Validation is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. We love the people who are involved in this project, and we'd love to have you on board, especially if you are just getting started or have never contributed to open-source before.
So here's to you, lovely person who wants to join us — this is how you can support us:
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.
See our sponsors for more information. JetBrains, Claude, Anthropic, OpenAI and Codex names and logos are trademarks of their respective owners.
Code released under the MIT license.
reactiveui/ReactiveUI.Validation is a public repo on GitHub by reactiveui. Reactive validation for ReactiveUI view models. Declare validation rules as observables over properties and bind the results to views on any supported .NET platform.
It declares the MIT license on GitHub.
Its maker tagged it for Windows. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-22. GitHub counts 8 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Image loading, caching & transforming library for Xamarin and Windows
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.
The automatic type-safe REST library for .NET. Refit turns a REST API into a C# interface and generates the HttpClient implementation, with support for HttpClientFactory, pluggable serializers and a testing package.
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.
An asynchronous, persistent key-value store for .NET desktop and mobile applications, backed by SQLite. Suited to both durable data such as user settings and cached data that expires, with optional encryption and System.Text.Json serialization.
Cross-platform building blocks for .NET applications. Provides service location and dependency resolution, logging, platform-neutral images, colours and geometry, and unit test and design mode detection.
A cross-platform sample application built with ReactiveUI. Camelotia is a file manager for cloud storage providers and local file systems, demonstrating reactive MVVM architecture, testable view models and shared code across desktop UI frameworks.
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/reactiveui/ReactiveUI.ValidationTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.