P11MessageBox Service
The
P11MessageBox is a powerful service component designed to display modal dialogs that halt the execution of calling code until the user interacts with the message box. It's ideal for prompting user decisions (e.g., Yes/No/Cancel), displaying critical information, or collecting user input via custom forms. It integrates with Bootstrap for consistent UI.
Note: The
P11MessageBox service requires a TpcMessageBox component to be present in your application's layout (e.g., in MainLayout.razor or App.razor) to render the dialog. This container component manages the display of the active message box.Usage: P11MessageBoxService Methods
| Method | Description | Parameters | Returns |
|---|---|---|---|
ShowOkAsync(string title, string message, DialogPurpose purpose) |
Displays a standard informational message box with a single "OK" button. |
|
Task<MessageBoxResult> (<code>Ok</code> or <code>None</code>) |
ShowYesNoAsync(string title, string message, DialogPurpose purpose) |
Displays a standard message box with "Yes" and "No" buttons for binary decisions. |
|
Task<MessageBoxResult> (<code>Yes</code>, <code>No</code>, or <code>None</code>) |
ShowYesNoCancelAsync(string title, string message, DialogPurpose purpose) |
Displays a standard message box with "Yes", "No", and "Cancel" buttons for actions that can be confirmed, denied, or aborted. |
|
Task<MessageBoxResult> (<code>Yes</code>, <code>No</code>, <code>Cancel</code>, or <code>None</code>) |
ShowAsync<TResult>(RenderFragment<Action<TResult>> content, string title) |
Displays a highly customizable message box using a provided <code>RenderFragment</code> for its content. The custom content is responsible for invoking the provided <code>Action<TResult></code> to set the dialog's result and close it. |
|
Task<TResult> (Completes with the custom result type.) |
ShowAsync<TComponent, TResult>(object parameters, string title) where TComponent : IComponent |
Displays a highly customizable message box by rendering a custom Blazor component (<code>TComponent</code>) inside the dialog. Parameters can be passed to the component via the <code>parameters</code> object. <code>TComponent</code> must expose a <code>[Parameter] Action<TResult></code> to set the dialog's result. |
|
Task<TResult> (Completes with the custom result type.) |
Underlying MessageBoxRequest Properties
When using the standard
ShowOkAsync, ShowYesNoAsync, or ShowYesNoCancelAsync methods, the service internally constructs a MessageBoxRequest using the following properties:| Property | Type | Default | Description |
|---|---|---|---|
Title |
string |
null |
Gets or sets the title displayed in the header of the message box. |
Purpose |
DialogPurpose |
DialogPurpose.Custom |
Gets or sets the purpose or style of the message box. This typically influences the default icon and visual styling (e.g., info, warning, error, question). |
IconClass |
string |
null |
Gets or sets an optional CSS class for a custom icon. If specified, this class overrides the default icon determined by the Purpose. |
Message |
string |
null |
Gets or sets the main message text to display in the body of a standard message box. This property is used for non-custom message boxes (e.g., OK-boxes). |
Buttons |
List<(string Text, MessageBoxResult Result)> |
null |
(Internal) Defines the text and associated result for the buttons displayed in the message box. Set by the standard Show...Async methods. |
CustomContent |
Func<Action<object>, RenderFragment> |
null |
(Internal) Used for custom message boxes to render dynamic Blazor content. Set by the ShowAsync methods. |
SetResultCallback |
Action<object> |
null |
(Internal) A callback action invoked by the TpcMessageBox component to deliver the user's selected result back to the awaiting service method. |