Using MessageBox

Installation

dotnet add package Nlnet.Avalonia.MessageBox --version 1.0.0-beta.4

Using standalone styled MessageBox

  • Import resource.

<ResourceInclude Source="avares://Nlnet.Avalonia.MessageBox/Assets/Themes.axaml" />
  • Synchronised use.

// WPF Standard: call messagebox synchronous.
private void OnClick(object? sender, RoutedEventArgs e)
{
    var result = MessageBox.Show("Hello, this is Nlnet MessageBox!", 
        "Welcome", Buttons.OkCancel, Images.Info);
    
    TbxResult.Text = result.ToString();
}
  • Asynchronous use.

// Avalonia Standard: call messagebox asynchronous.
private async void OnClick(object? sender, RoutedEventArgs e)
{
    var result  = await MessageBox.ShowAsync("Hello, this is Nlnet MessageBox :)", 
         "Welcome", Buttons.OkCancel, Images.Info);
    
    TbxResult.Text = result.ToString();
}

Using Acss-based MessageBox

The difference with standalone MessageBox styles is that Acss-based styles load different style resources. There is no difference in the way it is called.

<ResourceInclude 
    Source="avares://Nlnet.Avalonia.MessageBox/Assets/Themes.Acss.axaml" />

Using custom styles

You can still customise the theme and style of the MessageBox, in the same way as overriding the theme style of other Avalonia controls/windows.

Samples

We provide standalone MessageBox example code, visit it on Github.

Last updated