MessageService
The MessageService is a service that can be used to show MessageBars and Notifications (in a Notification Center as shown here in the demo site). It needs to be injected into a page or component before any of its methods can be called.
The MessageService is automatically registered in the DI provider with the .AddFluentUIComponents()
method call.
MessageBar provider
Messages are rendered by the <FluentMessageBarProvider />
. This component needs to be added to the layout of your application/site.
For a message bar that needs to be shown at the top of the screen, you typically do this in the MainLayout.razor
file at the location in
the HTML structure where you want the message bars to appear of the <main>
section like this:
<main>
<nav>
<!-- -->
</nav>
<div class="content">
<article id="article">
<FluentMessageBarProvider Section="MESSAGES_TOP"/>
@Body
</article>
</div>
</main>
IMPORTANT!!
For the
<FluentMessageBarProvider/>
to work porperly, it needs interactivity! If you are using "per page" interactivity or ASP.NET Core 8 or above with Server Side Rendering , make sure to add a@rendermode
to either the provider itself or the component the provider is placed in.
It is also possible to have message bars appear in a dialog or card. In that case you need to add the <FluentMessageBarProvider />
component to the specification the dialog or card using the Section
parameter as an identification.
You can then target a specific message bar by specifying the Section
parameter in the MessageService.ShowMessageBar()
/
MessageService.ShowMessageBarAsync()
methods.
See the MessageBar page for examples on how to use the messages and FluentMessageBar component.
MessageService Class
Properties
Name | Type | Default | Description |
---|---|---|---|
AllMessages | IEnumerable<Message> | Gets all messages. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
Clear | string section | void | Clear all messages (per section, if provided) from the message bar. |
Count | string section | int | Count the number of messages (per section, if provided) in the message bar . |
MessagesToShow | int count string section | IEnumerable<Message> | Retrieve messages to show in the message bar. |
Remove | Message message | void | Remove a message from the message bar. |
ShowMessageBar | string title | Message | Show a message based on the provided options in a message bar. |
ShowMessageBar | string title MessageIntent intent | Message | Show a message based on the provided options in a message bar. |
ShowMessageBar | string title MessageIntent intent string section | Message | Show a message based on the provided options in a message bar. |
ShowMessageBar | Action<MessageOptions> options | Message | Show a message based on the provided options in a message bar. |
ShowMessageBarAsync | string title | Task<Message> | Show a message based on the provided message options in a message bar. |
ShowMessageBarAsync | string title MessageIntent intent | Task<Message> | Show a message based on the provided message options in a message bar. |
ShowMessageBarAsync | string title MessageIntent intent string section | Task<Message> | Show a message based on the provided message options in a message bar. |
ShowMessageBarAsync | Action<MessageOptions> options | Task<Message> | Show a message based on the provided message options in a message bar. |
FluentMessageBarProvider Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
ClearAfterNavigation | bool | False | Clear all (shown and stored) messages when the user navigates to a new page. |
MaxMessageCount | int? | 5 | Maximum number of messages displayed. Rest is stored in memory to be displayed when an shown message is closed. Default value is 5 Set a value equal to or less than zero, to display all messages for this FluentMessageBarProvider.Section (or all categories if not set). |
NewestOnTop | bool | True | Display the newest messages on top (true) or on bottom (false). |
Section | string? | Display only messages for this section. | |
Type | MessageType | MessageBar | Displays messages as a single line (with the message only) or as a card (with the detailed message). |
FluentMessageBar Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
AllowDismiss | bool | True | Gets or sets the ability to dismiss the notification. Default is true. |
ChildContent | RenderFragment? | Gets or sets the message to be shown when not using the MessageService methods. | |
Content | Message | Gets or sets the actual message instance shown in the message bar. | |
FadeIn | bool | True | Gets or sets the fade in animation for the MessageBar. Default is true. |
Icon | Icon? | Preview:
| Gets or sets the icon to show in the message bar based on the intent of the message. See FluentMessageBar.Icon for more details. |
IconColor | Color? | Accent | Gets or sets the color of the icon. Only applied when intent is MessageBarIntent.Custom. Default is Color.Accent. |
Intent | MessageIntent? | Info | Gets or sets the intent of the message bar. Default is MessageIntent.Info. See MessageIntent for more details. |
Timestamp | DateTime? | Gets or sets the time on which the message was created. Default is DateTime.Now. Only used when MessageType is Notification. | |
Title | string? | Gets or sets the title. Most important info to be shown in the message bar. | |
Type | MessageType | MessageBar | Gets or sets the type of message bar. Default is MessageType.MessageBar. See MessageType for more details. |
Visible | bool | True | Gets or sets the visibility of the message bar. Default is true. |
Message Class
Properties
Name | Type | Default | Description |
---|---|---|---|
AllowDismiss | bool | True | Gets or sets whether the message bar is dismissible. |
Body | string? | Gets or sets the message to be shown in the message bar. | |
Intent | MessageIntent? | Info | Gets or sets the intent of the message bar. Default is MessageIntent.Info. See MessageIntent for more details. |
Link | ActionLink<Message>? | Gets or sets the link to be shown in the message bar (after the body). | |
Section | string | Indication of in which message bar the message needs to be shown. Default is null. | |
Timeout | int? | ||
Title | string? | Gets or sets the title. Most important info to be shown in the message bar. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
Close | void | Close the message bar. |