Component to display message-boxes.
Usually used via HxMessageBoxService
and HxMessageBoxHost
.
HxMessageBox
is a implementation component you use directly only in rare specific cases.IHxMessageBoxService
injected service and its
ShowAsync
method (or derived extension methods).Inject the IHxMessageBoxService
to your code and use one of it's methods to raise the message box:
Task<MessageBoxButtons> ShowAsync(MessageBoxRequest request)
- original methodTask<MessageBoxButtons> ShowAsync(string title, string text, MessageBoxButtons buttons = MessageBoxButtons.Ok, MessageBoxButtons? primaryButton = null, string customButtonText = null)
- extension methodTask<bool> ConfirmAsync(string title, string text)
- extension method
ShowAsync result: None
Confirm result:
@* <HxMessageBoxHost /> is in MainLayout.razor *@
<p>
<HxButton Text="MessageBox.ShowAsync()..." OnClick="OpenMessageBox" Color="ThemeColor.Primary" />
<HxButton Text="MessageBox.Confirm()..." OnClick="OpenConfirm" Color="ThemeColor.Primary" />
</p>
<p>
ShowAsync result: @showResult.ToString("g")<br />
Confirm result: @confirmResult
</p>
@code
{
[Inject] protected IHxMessageBoxService MessageBox { get; set; }
private MessageBoxButtons showResult;
private bool? confirmResult;
private async Task OpenMessageBox()
{
showResult = await MessageBox.ShowAsync("Info", "This is the text", MessageBoxButtons.OkCancel);
}
private async Task OpenConfirm()
{
confirmResult = await MessageBox.ConfirmAsync("Confirm", "Do you really want to ...?");
}
}
You should place the HxMessageBoxHost
component to MainLayout.razor
(or App.razor
) to make it work!
@inherits LayoutComponentBase
<HxMessageBoxHost />
@Body
Register required services using services.AddHxMessageBoxHost()
from Startup.cs
(Blazor Server) or Program.cs
(Blazor WebAssembly).
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddHxMessageBoxHost();
// ...
}
If you clear the Title
, HeaderTemplate
and set ShowCloseButton="false"
, the header won't show up.
Name | Type | Description |
---|---|---|
AdditionalAttributes | Dictionary<string, object> |
Additional attributes to be splatted onto an underlying HxModal . |
BodyTemplate | RenderFragment |
Body (content) template. |
Buttons | MessageBoxButtons |
Buttons to show. Default is MessageBoxButtons.Ok . |
CustomButtonText | string |
Text for MessageBoxButtons.Custom . |
HeaderTemplate | RenderFragment |
Header template (Header). |
ModalSettings | ModalSettings |
Settings for underlying HxModal component. |
OnClosed | EventCallback<MessageBoxButtons> |
Raised when the message box gets closed. Returns the button clicked. |
PrimaryButton | MessageBoxButtons? |
Primary button (if you want to override the default). |
PrimaryButtonSettings | ButtonSettings |
Settings for the dialog primary button. |
SecondaryButtonSettings | ButtonSettings |
Settings for dialog secondary button(s). |
ShowCloseButton | bool? |
Indicates whether to show the close button.
Default is taken from the underlying HxModal (true ). |
Text | string |
Content (body) text. |
Title | string |
Title text (Header). |
Method | Returns | Description |
---|---|---|
ShowAsync() | Task |
Displays the message box. |
Property | Type | Description |
---|---|---|
Defaults | MessageBoxSettings |
Application-wide defaults for HxButton and derived components. |
Displays message boxes initiated through IHxMessageBoxService
.
To be placed in root application component / main layout.