![]() |
VOOZH | about |
dotnet add package ReactiveUI.Avalonia --version 12.0.3
NuGet\Install-Package ReactiveUI.Avalonia -Version 12.0.3
<PackageReference Include="ReactiveUI.Avalonia" Version="12.0.3" />
<PackageVersion Include="ReactiveUI.Avalonia" Version="12.0.3" />Directory.Packages.props
<PackageReference Include="ReactiveUI.Avalonia" />Project file
paket add ReactiveUI.Avalonia --version 12.0.3
#r "nuget: ReactiveUI.Avalonia, 12.0.3"
#:package ReactiveUI.Avalonia@12.0.3
#addin nuget:?package=ReactiveUI.Avalonia&version=12.0.3Install as a Cake Addin
#tool nuget:?package=ReactiveUI.Avalonia&version=12.0.3Install as a Cake Tool
๐ Build
๐ Code Coverage
๐ #yourfirstpr
๐ alternate text is missing from this package README image
๐ NuGet
<br> <a href="https://github.com/reactiveui/reactiveui"> <img width="160" height="160" src="https://raw.githubusercontent.com/reactiveui/styleguide/master/logo/main.png"> </a> <br>
This package provides ReactiveUI bindings and helpers for the Avalonia UI framework, enabling you to build composable, cross-platform model-view-viewmodel (MVVM) applications for Windows, macOS, and Linux.
Install the packages that match your preferred dependency injection container. The core package is always required.
All libraries target multiple frameworks including .NET Standard 2.0 and modern .NET (.NET 8/9/10) for broad compatibility.
The recommended approach for new projects is to use the ReactiveUIBuilder via the UseReactiveUI and UseReactiveUIWith... extensions. This ensures consistent registration of schedulers, activation/binding hooks, and view discovery.
Namespaces to import in your startup:
using Avalonia; // AppBuilder
using ReactiveUI.Avalonia; // UseReactiveUI, RegisterReactiveUIViews* (core)
using ReactiveUI.Avalonia.Splat; // Autofac, DryIoc, Ninject, Microsoft.Extensions.DependencyInjection integrations
Minimal setup (no external DI container):
public static class Program
{
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
public static AppBuilder BuildAvaloniaApp() => AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI(rxui =>
{
// Optional: add custom registration here via rxui.WithRegistration(...)
})
.RegisterReactiveUIViewsFromEntryAssembly();
}
With Autofac:
public static AppBuilder BuildAvaloniaApp() => AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUIWithAutofac(
container =>
{
// Register your services/view models
// container.RegisterType<MainViewModel>();
},
withResolver: resolver =>
{
// Optional: access the Autofac resolver/lifetime scope
},
withReactiveUIBuilder: rxui =>
{
// Optional: add ReactiveUI customizations
})
.RegisterReactiveUIViewsFromEntryAssembly();
With DryIoc:
public static AppBuilder BuildAvaloniaApp() => AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUIWithDryIoc(
container =>
{
// container.Register<MainViewModel>(Reuse.Singleton);
},
withReactiveUIBuilder: rxui =>
{
// Optional ReactiveUI customizations
})
.RegisterReactiveUIViewsFromEntryAssembly();
With Microsoft.Extensions.DependencyInjection:
public static AppBuilder BuildAvaloniaApp() => AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUIWithMicrosoftDependencyResolver(
services =>
{
// services.AddSingleton<MainViewModel>();
},
withResolver: sp =>
{
// Optional: access ServiceProvider
})
;
Note: UseReactiveUIWithMicrosoftDependencyResolver(...) builds the ServiceProvider during setup, so make sure you register all services (including any IViewFor<T> views) in the services => { ... } callback.
With Ninject:
public static AppBuilder BuildAvaloniaApp() => AppBuilder
.Configure<App>()
.UsePlatformDetect()
.UseReactiveUIWithNinject(
kernel =>
{
// kernel.Bind<MainViewModel>().ToSelf().InSingletonScope();
},
withReactiveUIBuilder: rxui =>
{
// Optional ReactiveUI customizations
})
.RegisterReactiveUIViewsFromEntryAssembly();
Notes
UseReactiveUI sets RxApp.MainThreadScheduler to AvaloniaScheduler.Instance and registers the Avalonia-specific activation and binding services.RegisterReactiveUIViewsFromEntryAssembly() scans your entry assembly and registers any types implementing IViewFor<TViewModel> for view location/navigation.UseReactiveUI() without a DI container and register services into Splat directly if you prefer.You can configure a custom container using the generic UseReactiveUIWithDIContainer if you donโt use one of the provided integrations:
AppBuilder
.Configure<App>()
.UseReactiveUIWithDIContainer(
containerFactory: () => new MyContainer(),
containerConfig: container =>
{
// configure container
},
dependencyResolverFactory: container => new MySplatResolver(container))
.RegisterReactiveUIViewsFromEntryAssembly();
// View model
using ReactiveUI;
public class MyViewModel : ReactiveObject
{
private string _greeting = "Hello, Reactive World!";
public string Greeting
{
get => _greeting;
set => this.RaiseAndSetIfChanged(ref _greeting, value);
}
}
<UserControl x:Class="MyAvaloniaApp.Views.MainView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rxui="using:ReactiveUI.Avalonia">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="GreetingTextBlock" FontSize="24"/>
</StackPanel>
</UserControl>
// MainView.axaml.cs
using ReactiveUI;
using ReactiveUI.Avalonia;
using System.Reactive.Disposables;
public partial class MainView : ReactiveUserControl<MyViewModel>
{
public MainView()
{
InitializeComponent();
ViewModel = new MyViewModel();
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Greeting, v => v.GreetingTextBlock.Text)
.DisposeWith(disposables);
});
}
}
Key extension methods on AppBuilder:
UseReactiveUI() โ initialize ReactiveUI for Avalonia (scheduler, activation, bindings)UseReactiveUI(Action<ReactiveUIBuilder>) โ initialize with the ReactiveUIBuilder for additional configurationRegisterReactiveUIViews(params Assembly[]) โ scan and register views implementing IViewFor<T>RegisterReactiveUIViewsFromEntryAssembly() โ convenience overload to scan the entry assemblyRegisterReactiveUIViewsFromAssemblyOf<TMarker>() โ scan a specific assemblyUseReactiveUIWithDIContainer<TContainer>(...) โ bring-your-own container integration via an IDependencyResolverImportant types registered by default:
IActivationForViewFetcher ? AvaloniaActivationForViewFetcherIPropertyBindingHook ? AutoDataTemplateBindingHookICreatesCommandBinding ? AvaloniaCreatesCommandBindingICreatesObservableForProperty ? AvaloniaObjectObservableForPropertyRxApp.MainThreadScheduler set to AvaloniaScheduler.InstanceControls and helpers:
RoutedViewHost โ view host that displays the view for the current RoutingStateReactiveUserControl<TViewModel>, ReactiveWindow<TViewModel> โ base classes for reactive viewsExtension methods on AppBuilder (namespace Avalonia.ReactiveUI.Splat):
UseReactiveUIWithAutofac(Action<ContainerBuilder> containerConfig, Action<AutofacDependencyResolver>? withResolver = null)UseReactiveUIWithAutofac(Action<ContainerBuilder> containerConfig, Action<AutofacDependencyResolver>? withResolver = null, Action<ReactiveUIBuilder>? withReactiveUIBuilder = null)What it does:
Splat with Autofac, initializes ReactiveUI for Avalonia, builds your container, and optionally exposes the Autofac resolver.Extension methods on AppBuilder (namespace ReactiveUI.Avalonia.Splat):
UseReactiveUIWithDryIoc(Action<Container> containerConfig)UseReactiveUIWithDryIoc(Action<Container> containerConfig, Action<ReactiveUIBuilder>? withReactiveUIBuilder = null)What it does:
Splat to DryIoc, initializes ReactiveUI for Avalonia, and lets you register services on the container.Extension methods on AppBuilder (namespace ReactiveUI.Avalonia.Splat):
UseReactiveUIWithMicrosoftDependencyResolver(Action<IServiceCollection> containerConfig, Action<IServiceProvider?>? withResolver = null)UseReactiveUIWithMicrosoftDependencyResolver(Action<IServiceCollection> containerConfig, Action<IServiceProvider?>? withResolver = null, Action<ReactiveUIBuilder>? withReactiveUIBuilder = null)What it does:
Splat using IServiceCollection/ServiceProvider, initializes ReactiveUI for Avalonia, and exposes the built provider if you need it.Extension methods on AppBuilder (namespace ReactiveUI.Avalonia.Splat):
UseReactiveUIWithNinject(Action<StandardKernel> containerConfig)UseReactiveUIWithNinject(Action<StandardKernel> containerConfig, Action<ReactiveUIBuilder>? withReactiveUIBuilder = null)What it does:
Splat to Ninject, initializes ReactiveUI for Avalonia, and lets you configure bindings on the kernel.Welcome to the ReactiveUI.Avalonia guide! This tutorial walks you through setting up an Avalonia app with ReactiveUI. We start with the basics and build up to a reactive application.
ReactiveUI.Avalonia provides the necessary bindings and helpers to seamlessly integrate the ReactiveUI MVVM framework with your Avalonia projects, enabling elegant, testable, and maintainable code.
Add the ReactiveUI.Avalonia package to your Avalonia application project file.
<PackageReference Include="ReactiveUI.Avalonia" Version="11.3.0" />
Use the builder-based setup shown above (see "Recommended setup"). For a minimal variant:
AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.RegisterReactiveUIViewsFromEntryAssembly();
using ReactiveUI;
public class MyViewModel : ReactiveObject
{
private string _greeting;
public string Greeting
{
get => _greeting;
set => this.RaiseAndSetIfChanged(ref _greeting, value);
}
public MyViewModel() => Greeting = "Hello, Reactive World!";
}
<UserControl x:Class="MyAvaloniaApp.Views.MainView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rxui="using:ReactiveUI.Avalonia">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="GreetingTextBlock" FontSize="24"/>
</StackPanel>
</UserControl>
// MainView.axaml.cs
using ReactiveUI;
using ReactiveUI.Avalonia;
using System.Reactive.Disposables;
public partial class MainView : ReactiveUserControl<MyViewModel>
{
public MainView()
{
InitializeComponent();
ViewModel = new MyViewModel();
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Greeting, v => v.GreetingTextBlock.Text)
.DisposeWith(disposables);
});
}
}
Add a command to the view model and bind it in the view.
using ReactiveUI;
using System;
using System.Reactive;
public class MyViewModel : ReactiveObject
{
public ReactiveCommand<Unit, Unit> GenerateGreetingCommand { get; }
private string _greeting = "Hello, Reactive World!";
public string Greeting
{
get => _greeting;
set => this.RaiseAndSetIfChanged(ref _greeting, value);
}
public MyViewModel()
{
GenerateGreetingCommand = ReactiveCommand.Create(() =>
{
Greeting = $"Hello from Avalonia! The time is {DateTime.Now.ToLongTimeString()}";
});
}
}
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="GreetingTextBlock" FontSize="24"/>
<Button x:Name="GenerateGreetingButton" Content="Generate" Margin="0,20,0,0"/>
</StackPanel>
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Greeting, v => v.GreetingTextBlock.Text)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.GenerateGreetingCommand, v => v.GenerateGreetingButton)
.DisposeWith(disposables);
});
RoutedViewHostSet up a router and display views based on navigation state.
using ReactiveUI;
public class AppViewModel : ReactiveObject, IScreen
{
public RoutingState Router { get; } = new RoutingState();
public AppViewModel() => Router.Navigate.Execute(new MyViewModel());
}
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rxui="using:ReactiveUI.Avalonia"
x:Class="MyAvaloniaApp.MainWindow">
<Grid>
<rxui:RoutedViewHost Router="{Binding Router}" />
</Grid>
</Window>
Register views manually or scan assemblies:
using ReactiveUI;
using ReactiveUI.Avalonia;
using Splat;
Locator.CurrentMutable.Register(() => new MainView(), typeof(IViewFor<MyViewModel>));
// or:
AppBuilder.Configure<App>().UseReactiveUI().RegisterReactiveUIViewsFromEntryAssembly();
We want to thank the following contributors and libraries that help make ReactiveUI.Avalonia possible:
The core team members, ReactiveUI contributors and contributors in the ecosystem do this open-source work in their free time. If you use ReactiveUI, a serious task, and you'd like us to invest more time on it, please donate. This project increases your income/productivity too. It makes development and applications faster and it reduces the required bandwidth.
This is how we use the donations:
If you have a question, please see if any discussions in our GitHub Discussions or GitHub issues have already answered it.
If you want to discuss something or just need help, here is our Slack room, where there are always individuals looking to help out!
Please do not open GitHub issues for support requests.
Please do not open GitHub issues for general support requests.
ReactiveUI.Avalonia is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use.
If you want to submit pull requests please first open a GitHub issue to discuss. We are first time PR contributors friendly.
See Contribution Guidelines for further information how to contribute changes.
ReactiveUI.Avalonia is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on ReactiveUI.Avalonia:
| Package | Downloads |
|---|---|
|
Zafiro.Avalonia
UI components, controls, dialogs, behaviors, and helpers for Avalonia applications. Includes reactive patterns, cross-platform support (desktop, mobile, browser), and source generators. |
|
|
Zafiro.Avalonia.Dialogs
UI components, controls, dialogs, behaviors, and helpers for Avalonia applications. Includes reactive patterns, cross-platform support (desktop, mobile, browser), and source generators. |
|
|
Zafiro.Avalonia.DataViz
UI components, controls, dialogs, behaviors, and helpers for Avalonia applications. Includes reactive patterns, cross-platform support (desktop, mobile, browser), and source generators. |
|
|
ArtemisRGB.UI.Shared
Package Description |
|
|
Macabresoft.AvaloniaEx
A theme and control library for Avalonia. |
Showing the top 20 popular GitHub repositories that depend on ReactiveUI.Avalonia:
| Repository | Stars |
|---|---|
|
2dust/v2rayN
A GUI client for Windows, Linux and macOS, support Xray and sing-box and others
|
|
|
BeyondDimension/SteamTools
๐ ใWatt Toolkitใๆฏไธไธชๅผๆบ่ทจๅนณๅฐ็ๅคๅ่ฝ Steam ๅทฅๅ
ท็ฎฑใ
|
|
|
rmcrackan/Libation
Libation: Liberate your Library
|
|
|
timschneeb/GalaxyBudsClient
Unofficial Galaxy Buds Manager for Windows, macOS, Linux, and Android
|
|
|
0x90d/videoduplicatefinder
Video Duplicate Finder - Crossplatform
|
|
|
WalletWasabi/WalletWasabi
Open-source, non-custodial, privacy preserving Bitcoin wallet for Windows, Linux, and Mac.
|
|
|
TEdit/Terraria-Map-Editor
TEdit - Terraria Map Editor - TEdit is a stand alone, open source map editor for Terraria. It lets you edit maps just like (almost) paint! It also lets you change world settings (time, bosses downed etc), edit chests and change sign, make epic dungeons, castles, cities, and add rewards for your adventurers!
|
|
|
Mapsui/Mapsui
Mapsui is a .NET Map component for: MAUI, Avalonia, Uno Platform, Blazor, WPF, WinUI, Windows Forms, Eto Forms, .NET for Android and .NET for iOS
|
|
|
irihitech/Ursa.Avalonia
Ursa is an enterprise level UI library for building cross-platform applications with Avalonia UI.
|
|
|
wieslawsoltes/Dock
A docking layout system.
|
|
|
b-editor/beutl
Cross-platform video editing (compositing) software.
|
|
|
Artemis-RGB/Artemis
Provides advanced unified lighting across many different brands RGB peripherals
|
|
|
Decimation/SmartImage
Reverse image search tool (SauceNao, IQDB, Ascii2D, trace.moe, and more)
|
|
|
AtomUI/AtomUI
AtomUI leverages Avalonia's robust cross-platform capabilities to implement the Ant Design system for .NET, dedicated to delivering its refined design language and efficient user experience to cross-platform desktop application development.
|
|
|
wieslawsoltes/Svg.Skia
An SVG rendering library.
|
|
|
AvaloniaUI/avalonia-dotnet-templates
Avalonia Templates for `dotnet new`
|
|
|
PhantomGamers/SFP
This utility is designed to allow you to apply skins to the modern Steam client
|
|
|
AvaloniaUI/Avalonia.Markup.Declarative
Provides helpers for declarative ui in C#
|
|
|
Monitor221hz/Pandora-Behaviour-Engine-Plus
Patcher for behavior, character, and skeleton project files for Skyrim Special Edition.
|
|
|
whistyun/Markdown.Avalonia
render markdown with Avalonia UI
|