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
AllMessagesIEnumerable<Message>
Gets all messages.

Methods

Name
Parameters
Type
Description
Clearstring section
void
Clear all messages (per section, if provided) from the message bar.
Countstring section
int
Count the number of messages (per section, if provided) in the message bar .
MessagesToShowint count
string section
IEnumerable<Message>
Retrieve messages to show in the message bar.
RemoveMessage message
void
Remove a message from the message bar.
ShowMessageBarstring title
Message
Show a message based on the provided options in a message bar.
ShowMessageBarstring title
MessageIntent intent
Message
Show a message based on the provided options in a message bar.
ShowMessageBarstring title
MessageIntent intent
string section
Message
Show a message based on the provided options in a message bar.
ShowMessageBarAction<MessageOptions> options
Message
Show a message based on the provided options in a message bar.
ShowMessageBarAsyncstring title
Task<Message>
Show a message based on the provided message options in a message bar.
ShowMessageBarAsyncstring title
MessageIntent intent
Task<Message>
Show a message based on the provided message options in a message bar.
ShowMessageBarAsyncstring title
MessageIntent intent
string section
Task<Message>
Show a message based on the provided message options in a message bar.
ShowMessageBarAsyncAction<MessageOptions> options
Task<Message>
Show a message based on the provided message options in a message bar.

FluentMessageBarProvider Class

Parameters

Name
Type
Default
Description
ClearAfterNavigationbool
False
Clear all (shown and stored) messages when the user navigates to a new page.
MaxMessageCountint?
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).
NewestOnTopbool
True
Display the newest messages on top (true) or on bottom (false).
Sectionstring?
Display only messages for this section.
TypeMessageType
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
AllowDismissbool
True
Gets or sets the ability to dismiss the notification.
Default is true.
ChildContentRenderFragment?
Gets or sets the message to be shown when not using the MessageService methods.
ContentMessage
Gets or sets the actual message instance shown in the message bar.
FadeInbool
True
Gets or sets the fade in animation for the MessageBar.
Default is true.
IconIcon?
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.
IconColorColor?
Accent
Gets or sets the color of the icon.
Only applied when intent is MessageBarIntent.Custom.
Default is Color.Accent.
IntentMessageIntent?
Info
Gets or sets the intent of the message bar.
Default is MessageIntent.Info. See MessageIntent for more details.
TimestampDateTime?
Gets or sets the time on which the message was created.
Default is DateTime.Now.
Only used when MessageType is Notification.
Titlestring?
Gets or sets the title.
Most important info to be shown in the message bar.
TypeMessageType
MessageBar
Gets or sets the type of message bar.
Default is MessageType.MessageBar. See MessageType for more details.
Visiblebool
True
Gets or sets the visibility of the message bar.
Default is true.

Message Class

Properties

Name
Type
Default
Description
AllowDismissbool
True
Gets or sets whether the message bar is dismissible.
Bodystring?
Gets or sets the message to be shown in the message bar.
IntentMessageIntent?
Info
Gets or sets the intent of the message bar.
Default is MessageIntent.Info.
See MessageIntent for more details.
LinkActionLink<Message>?
Gets or sets the link to be shown in the message bar (after the body).
Sectionstring
Indication of in which message bar the message needs to be shown. Default is null.
Timeoutint?
Titlestring?
Gets or sets the title.
Most important info to be shown in the message bar.

Methods

Name
Parameters
Type
Description
Closevoid
Close the message bar.
MessageBar
Notification
Neutral
Accent
Warning
Info
Error
Success
Fill
FillInverse
Lightweight
Disabled
Custom
Info
Warning
Error
Success
Custom
MessageBar
Notification
Info
Warning
Error
Success
Custom
Filled.Size20.Info
An error has occurred. This application may no longer respond until reloaded. Reload 🗙