Disorol.Avalonia.DialogBoxBuilder 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Disorol.Avalonia.DialogBoxBuilder --version 1.0.0
                    
NuGet\Install-Package Disorol.Avalonia.DialogBoxBuilder -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Disorol.Avalonia.DialogBoxBuilder" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Disorol.Avalonia.DialogBoxBuilder" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Disorol.Avalonia.DialogBoxBuilder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Disorol.Avalonia.DialogBoxBuilder --version 1.0.0
                    
#r "nuget: Disorol.Avalonia.DialogBoxBuilder, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Disorol.Avalonia.DialogBoxBuilder@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Disorol.Avalonia.DialogBoxBuilder&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Disorol.Avalonia.DialogBoxBuilder&version=1.0.0
                    
Install as a Cake Tool

Avalonia.DialogBuilder

A lightweight dialog builder library for Avalonia applications that provides a fluent interface for creating customizable dialog windows.

Features

  • Fluent API for dialog configuration
  • Pre-styled dialog types (Error, Warning, Information, Success)
  • Support for multiple buttons
  • Custom content support (text or controls)
  • Flexible styling and layout options
  • Global dialog settings

Getting Started

Installation

dotnet add package Avalonia.DialogBuilder

Dialog Setup with ReactiveUI

To use dialogs in your application, you need to set up three components:

1. Window Class

Your window must inherit from ReactiveWindow<TViewModel> where TViewModel is your window's view model type:

public partial class MainWindow : ReactiveWindow<MainWindowViewModel>

2. ViewModel Setup

In your window's view model, declare an Interaction property that will handle dialog operations:

public Interaction<DialogBoxViewModel, DialogBoxResult?> ShowDialog { get; } = new();

This property acts as a bridge between your view model and the actual dialog window.

3. Dialog Handler in Window

In your window's code-behind, implement the dialog showing logic:

public MainWindow()
{
    InitializeComponent();
    
    // Register dialog handler
    this.WhenActivated(action => 
        action(ViewModel!.ShowDialog.RegisterHandler(DoShowDialogAsync)));
}

private async Task DoShowDialogAsync(
    IInteractionContext<DialogBoxViewModel, DialogBoxResult?> interaction)
{
    var dialog = new DialogBoxView
    {
        DataContext = interaction.Input
    };

    var result = await dialog.ShowDialog<DialogBoxResult?>(this);
    interaction.SetOutput(result);
}

This setup creates a proper MVVM-friendly dialog system

Basic Usage

Simple dialog with text:

var builder = new DialogBoxViewModelBuilder().SetText("Do you want to save changes?")
                                             .SetButtons(
                                                 new DialogButtonBase { Text = "Save", CommandParameter = true },
                                                 new DialogButtonBase { Text = "Cancel", CommandParameter = false });
var director = new WarningDialogBoxDirector();
DialogBoxViewModel dialogBoxViewModel = director.Build(builder);
DialogBoxResult result = await ShowTestDialog.Handle(dialogBoxViewModel);

if (result.Parameter is true)
{
    // Handle save
}

Pre-styled error dialog:

var builder = new DialogBoxViewModelBuilder().SetText("Failed to connect to the server.")
                                             .SetButtons(
                                                 new DialogButtonBase { Text = "OK" });
var director = new ErrorDialogBoxDirector();
DialogBoxViewModel dialogBoxViewModel = director.Build(builder);
await ShowTestDialog.Handle(dialogBoxViewModel);

Dialog with custom control:

var viewModel = new TestViewModel();
var view = new TextView();
view.DataContext = viewModel;
var builder = new DialogBoxViewModelBuilder().SetControl(view)
                                             .SetButtons(new DialogButtonBase { Text = "Close" });
var director = new InformationDialogBoxDirector();
DialogBoxViewModel dialogBoxViewModel = director.Build(builder);
await ShowTestDialog.Handle(dialogBoxViewModel);

Customization

Styling and layout:

var builder = new DialogBoxViewModelBuilder()
    .SetMaxWidth(500)
    .SetMaxHeight(400)
    .SetTextFontSize(14)
    .SetButtonTextFontSize(12)
    .SetButtonHeight(32)
    .SetCanResize(true)
    .Build();

Global dialog titles:

ErrorDialogBoxDirector.Title = "Application Error";
WarningDialogBoxDirector.Title = "Warning";
InformationDialogBoxDirector.Title = "Information";
SuccessDialogBoxDirector.Title = "Success";

Example Project

The repository includes a TestingProject that demonstrates:

  • Complete setup of ReactiveUI Interactions for dialog handling
  • Practical examples of using Avalonia.DialogBuilder in a real application
  • Implementation of various dialog types and configurations

You can use this project as a reference for integrating the library into your own applications.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 235 4/14/2025
1.0.1 180 4/10/2025
1.0.0 172 4/10/2025