### Complete Configuration Example with Autofac Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/configuration.md A comprehensive example demonstrating how to configure ReactiveUI with Autofac for dependency injection, including registering ViewModels, Views, and Services, along with state persistence setup. ```csharp public static class Program { public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); public static AppBuilder BuildAvaloniaApp() { return AppBuilder .Configure() .UsePlatformDetect() .WithInterFont() .UseReactiveUIWithAutofac( containerConfig: container => { // Register ViewModels container.RegisterType().AsSelf().SingleInstance(); container.RegisterType().AsSelf(); // Register Views container.RegisterType().As>(); container.RegisterType().As>(); // Register Services container.RegisterType().As().SingleInstance(); container.RegisterType().AsSelf().SingleInstance(); }, withReactiveUIBuilder: rxui => { // Optional additional configuration }) .RegisterReactiveUIViewsFromEntryAssembly(); } } public partial class App : Application { public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IControlledApplicationLifetime lifetime) { var suspendHelper = new AutoSuspendHelper(lifetime); RxSuspension.SuspensionHost.ShouldPersistState .SelectMany(_ => SaveStateAsync()) .Subscribe(); suspendHelper.OnFrameworkInitializationCompleted(); } base.OnFrameworkInitializationCompleted(); } private async Task SaveStateAsync() { // Save application state return Unit.Default; } } ``` -------------------------------- ### Quick example: first reactive view Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/README.md Demonstrates a basic setup for a reactive view model and its corresponding Avalonia view, including data binding. ```csharp // 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); } } ``` ```xml ``` ```csharp // MainView.axaml.cs using ReactiveUI; using ReactiveUI.Avalonia; using System.Reactive.Disposables; public partial class MainView : ReactiveUserControl { public MainView() { InitializeComponent(); ViewModel = new MyViewModel(); this.WhenActivated(disposables => { this.OneWayBind(ViewModel, vm => vm.Greeting, v => v.GreetingTextBlock.Text) .DisposeWith(disposables); }); } } ``` -------------------------------- ### Setup With Ninject Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Setup for ReactiveUI.Avalonia using Ninject for dependency injection. ```csharp .UseReactiveUIWithNinject(kernel => { kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind>().To(); }) ``` -------------------------------- ### Setup With Autofac Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Setup for ReactiveUI.Avalonia using Autofac for dependency injection. ```csharp .UseReactiveUIWithAutofac(container => { container.RegisterType(); container.RegisterType(); }) .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### Setup With DryIoc Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Setup for ReactiveUI.Avalonia using DryIoc for dependency injection. ```csharp .UseReactiveUIWithDryIoc(container => { container.Register(Reuse.Singleton); container.Register(); }) ``` -------------------------------- ### Rebase and force push Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/CONTRIBUTING.md Example of how to rebase and force push to update a PR if it gets outdated. ```shell git rebase master -i git push origin my-fix-branch -f ``` -------------------------------- ### Setup With Microsoft DI Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Setup for ReactiveUI.Avalonia using Microsoft's built-in dependency injection. ```csharp .UseReactiveUIWithMicrosoftDependencyResolver(services => { services.AddSingleton(); services.AddSingleton(); }) ``` -------------------------------- ### ViewModel and Navigation Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ViewHosts.md Example ViewModel with RoutingState and navigation commands. ```csharp // ViewModel public class AppViewModel : ReactiveObject, IScreen { public RoutingState Router { get; } public AppViewModel() { Router = new RoutingState(); Router.Navigate.Execute(new HomeViewModel()); } } // Navigation // Assuming 'Router' is accessible, e.g., from the ViewModel // Router.Navigate.Execute(new DetailsViewModel()); ``` -------------------------------- ### UseReactiveUI Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/AppBuilderExtensions.md Example of configuring Avalonia AppBuilder with ReactiveUI and registering views. ```csharp public static AppBuilder BuildAvaloniaApp() => AppBuilder .Configure() .UsePlatformDetect() .UseReactiveUI(rxui => { // Optional: add custom registration here via rxui.WithRegistration(...) }) .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### View Registration Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ViewHosts.md Examples of manual and automatic view registration. ```csharp // Manual registration Locator.CurrentMutable.Register( () => new MainView(), typeof(IViewFor)); // With contract Locator.CurrentMutable.Register( () => new MainViewAdvanced(), typeof(IViewFor), "Advanced"); // Automatic scanning AppBuilder.Configure() .UseReactiveUI() .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### RegisterReactiveUIViewsFromEntryAssembly Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/AppBuilderExtensions.md Example of using RegisterReactiveUIViewsFromEntryAssembly during application startup. ```csharp AppBuilder.Configure() .UsePlatformDetect() .UseReactiveUI() .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### RegisterReactiveUIViews Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/AppBuilderExtensions.md Example of registering ReactiveUI views from specific assemblies. ```csharp // Register views from specific assemblies AppBuilder.Configure() .RegisterReactiveUIViews(typeof(MyView).Assembly, typeof(OtherView).Assembly); ``` -------------------------------- ### Service Registration During Setup Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Registers a service instance during the ReactiveUI setup. ```csharp .UseReactiveUI(rxui => { rxui.WithRegistration(splat => { splat.RegisterConstant(new MyService()); }); }) ``` -------------------------------- ### Minimal Setup (No DI Container) Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/configuration.md This is the minimal setup for ReactiveUI.Avalonia without using an external DI container. It uses Splat for service location and automatically discovers views from the entry assembly. ```csharp public static AppBuilder BuildAvaloniaApp() => AppBuilder .Configure() .UsePlatformDetect() .UseReactiveUI() .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### Reactive Command Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of creating a basic reactive command that can be executed. ```csharp public ReactiveCommand MyCommand { get; } public MyViewModel() { MyCommand = ReactiveCommand.Create(() => { // Handle click }); } ``` -------------------------------- ### Avalonia XAML Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ViewHosts.md Example of how to use RoutedViewHost in Avalonia XAML. ```xml ``` -------------------------------- ### Minimal Setup Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/README.md Sets up the Avalonia application with ReactiveUI integration. ```csharp public static class Program { public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); public static AppBuilder BuildAvaloniaApp() => AppBuilder .Configure() .UsePlatformDetect() .UseReactiveUI() .RegisterReactiveUIViewsFromEntryAssembly(); } ``` -------------------------------- ### Property as Observable Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of getting an observable stream from a control's property using GetSubject. ```csharp var subject = textBox.GetSubject(TextBox.TextProperty); subject .Debounce(TimeSpan.FromMilliseconds(500)) .Subscribe(text => Debug.WriteLine($"Search: {text}")); ``` -------------------------------- ### Commands Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/README.md Shows how to define and create a ReactiveCommand. ```csharp public ReactiveCommand MyCommand { get; } public MyViewModel() { MyCommand = ReactiveCommand.Create(() => { // Handle command }); } ``` -------------------------------- ### ReactiveCommand Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/types.md Example of creating and using a ReactiveCommand. ```csharp public ReactiveCommand GenerateGreetingCommand { get; } public ViewModel() { GenerateGreetingCommand = ReactiveCommand.Create(() => { Greeting = "Hello!"; }); } ``` -------------------------------- ### Minimal setup (no external DI container) Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/README.md Basic ReactiveUI setup using AppBuilder without integrating an external dependency injection container. ```csharp public static class Program { public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); public static AppBuilder BuildAvaloniaApp() => AppBuilder .Configure() .UsePlatformDetect() .UseReactiveUI(rxui => { // Optional: add custom registration here via rxui.WithRegistration(...) }) .RegisterReactiveUIViewsFromEntryAssembly(); } ``` -------------------------------- ### Example Usage of ReactiveWindow Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ReactiveControls.md An example demonstrating how to use ReactiveWindow in a view, including ViewModel binding and activation handling. ```csharp public partial class MainWindow : ReactiveWindow { public MainWindow() { InitializeComponent(); ViewModel = new MainViewModel(); this.WhenActivated(disposables => { this.OneWayBind(ViewModel, vm => vm.Title, v => v.Title) .DisposeWith(disposables); }); } } ``` -------------------------------- ### Navigation Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/README.md Demonstrates how to set up navigation using RoutingState and RoutedViewHost. ```csharp public class AppViewModel : ReactiveObject, IScreen { public RoutingState Router { get; } = new RoutingState(); } // In view: // In code: Router.Navigate.Execute(new DetailViewModel()); ``` -------------------------------- ### Constructor Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/AutoSuspendHelper.md Example of how to initialize AutoSuspendHelper with an IControlledApplicationLifetime. ```csharp public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IControlledApplicationLifetime lifetime) { var suspendHelper = new AutoSuspendHelper(lifetime); suspendHelper.OnFrameworkInitializationCompleted(); } base.OnFrameworkInitializationCompleted(); } ``` -------------------------------- ### State Persistence Setup Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Sets up state persistence for the application using AutoSuspendHelper and RxSuspension. ```csharp public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IControlledApplicationLifetime lifetime) { var suspendHelper = new AutoSuspendHelper(lifetime); RxSuspension.SuspensionHost.ShouldPersistState .SelectMany(_ => SaveStateAsync()) .Subscribe(); suspendHelper.OnFrameworkInitializationCompleted(); } base.OnFrameworkInitializationCompleted(); } private async Task SaveStateAsync() { var state = new { /* state */ }; var json = JsonConvert.SerializeObject(state); await File.WriteAllTextAsync("state.json", json); return Unit.Default; } ``` -------------------------------- ### Ninject Integration Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/DIContainerIntegrations.md An example of how to use the UseReactiveUIWithNinject method. ```csharp using ReactiveUI.Avalonia.Splat; using Ninject; AppBuilder.Configure() .UsePlatformDetect() .UseReactiveUIWithNinject( containerConfig: kernel => { kernel.Bind().ToSelf().InSingletonScope(); kernel.Bind>().To().InSingletonScope(); }, withReactiveUIBuilder: rxui => { // Optional ReactiveUI customizations }) .RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### Microsoft.Extensions.DependencyInjection Integration Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/DIContainerIntegrations.md An example of how to use the UseReactiveUIWithMicrosoftDependencyResolver method. ```csharp using ReactiveUI.Avalonia.Splat; using Microsoft.Extensions.DependencyInjection; AppBuilder.Configure() .UsePlatformDetect() .UseReactiveUIWithMicrosoftDependencyResolver( containerConfig: services => { services.AddSingleton(); services.AddSingleton(); }, withResolver: serviceProvider => { // Access the built ServiceProvider if needed }, withReactiveUIBuilder: rxui => { // Optional ReactiveUI customizations }); ``` -------------------------------- ### Window Template Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of creating a ReactiveWindow in C# with title binding. ```csharp public partial class MainWindow : ReactiveWindow { public MainWindow() { InitializeComponent(); ViewModel = new MainViewModel(); this.WhenActivated(disposables => { this.OneWayBind(ViewModel, vm => vm.Title, v => v.Title) .DisposeWith(disposables); }); } } ``` -------------------------------- ### BindingValue Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/types.md Example demonstrating the usage of BindingValue. ```csharp var bindingValue = new BindingValue("text"); if (bindingValue.HasValue) { var text = bindingValue.Value; // "text" } ``` -------------------------------- ### View Navigation With Contracts Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of using view contracts for navigation, showing registration and usage. ```csharp // Register with contract [ViewContract("Advanced")] public class DetailsViewAdvanced : ReactiveUserControl { } // Use contract ``` -------------------------------- ### Basic Navigation Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of setting up basic view navigation using RoutingState in a ViewModel and RoutedViewHost in XAML. ```csharp // ViewModel public class AppViewModel : ReactiveObject, IScreen { public RoutingState Router { get; } = new RoutingState(); public void NavigateToDetails() => Router.Navigate.Execute(new DetailsViewModel()); } // XAML ``` -------------------------------- ### Async Command Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example of creating a reactive command that executes an asynchronous operation. ```csharp public ReactiveCommand FetchDataCommand { get; } public MyViewModel() { FetchDataCommand = ReactiveCommand.CreateFromTask(async () => { return await FetchDataAsync(); }); } ``` -------------------------------- ### Registering Views Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/README.md Examples of how to register views with the Locator for navigation. ```csharp using ReactiveUI; using ReactiveUI.Avalonia; using Splat; Locator.CurrentMutable.Register(() => new MainView(), typeof(IViewFor)); // or: AppBuilder.Configure().UseReactiveUI().RegisterReactiveUIViewsFromEntryAssembly(); ``` -------------------------------- ### Example Usage of ReactiveUserControl Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ReactiveControls.md An example demonstrating how to use ReactiveUserControl in a view, including ViewModel binding and activation handling. ```csharp public partial class MainView : ReactiveUserControl { public MainView() { InitializeComponent(); ViewModel = new MainViewModel(); 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); }); } } ``` -------------------------------- ### Reactive Programming Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/Architecture.md An example demonstrating the use of Observables, Select, ObserveOn, and Subscribe for handling asynchronous sequences and UI updates. ```csharp observable .Select(x => Process(x)) .ObserveOn(AvaloniaScheduler.Instance) .Subscribe(value => UpdateUI(value)); ``` -------------------------------- ### ViewModelViewHost XAML Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/api-reference/ViewHosts.md Example of using ViewModelViewHost in XAML to display a ViewModel with its associated view and default content. ```xaml ``` -------------------------------- ### Push branch to GitHub Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/CONTRIBUTING.md Example of how to push a local branch to GitHub. ```shell git push origin my-fix-branch ``` -------------------------------- ### View Contracts Example Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/configuration.md Defining and using view contracts for multiple view implementations. ```csharp [ViewContract("Advanced")] public partial class MainViewAdvanced : ReactiveUserControl { // ... } ``` ```xml ``` -------------------------------- ### XAML View Source: https://github.com/reactiveui/reactiveui.avalonia/blob/main/_autodocs/QuickReference.md Example XAML for a ReactiveUserControl, defining UI elements. ```xml