# Using MessageBox

## Installation

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

## Using standalone styled MessageBox

* Import resource.

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

* Synchronised use.

```csharp
// 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.

```csharp
// 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.

```xml
<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

{% hint style="success" %}
We provide standalone MessageBox example code, visit it on [Github](https://github.com/liwuqingxin/Avalonia.Css/tree/main/samples/Nlnet.Avalonia.MessageBox.Samples).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.en.avalonia.css.nlnet.net/documentation/zhu-ti-bang-zhu/ru-he-shi-yong-messagebox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
