MessageBar

IMPORTANT!!

MessageBars 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:

For the MessageBars to work properly, the <FluentMessageBarProvider/> needs interactivity! If you are using "per page" interactivity, make sure to add a @rendermode to either the provider itself or the component the provider is placed in.

<main>
    <nav>
        <!-- -->
    </nav>
    <div class="content">
        <article id="article">
            <FluentMessageBarProvider Section="MESSAGES_TOP"/>
            @Body
        </article>
    </div>
</main>

Sections

You can use multiple message bar providers in a single page/app. In the example below you can add a message bar on the top of the window, but also in the notification center or in a dialog. An area to display messages in is called a Section. You can specify in wich Section you want your message to appear in through the MessageOptions.

Clear message bars on navigation

By default, message bars will not be removed when navigating to another page. This can be changed by setting the ClearAfterNavigation parameter to true on a FluentMenuProvider. When using multiple providers (see Sections above), the parameter needs to be set for each provider individually. You can also set the behavior on a per message basis by using the same parameter of the MessageOptions class.

Examples

Message Service

Example

Click on these buttons to display a message (max 5) in the top, in the Notification Center (top/right bell icon) or in a dialog (max 1).
If you click on "Add in a dialog" multiple times, you will see that only one message is displayed. Once you dismiss that one, the next one will be displayed.

Using the MessageService is the advised way to use message bars.

Add on top Add in Notification Center Add in a dialog Add non-dismissible on top Clear all alerts
Download: 

Timed Messages

Example

These message automatically dismiss after a set amount of time.

Add on top (4 sec) Add in Notification Center (3 sec) Add in a dialog (5 sec)
Download: 

MessageBar with options

Example

Click on the button to display a message (max 5) utilizing the MessageOptions class.

Display Clear all messages
Download: 

Simple messages

Example

This example show the different intents that can be shown in a MessageBar. This example does not use the MessageBarService.

Descriptive title Message providing information to the user with actionable insights.
Descriptive title Message providing information to the user with actionable insights.
Descriptive title Message providing information to the user with actionable insights.
Descriptive title Message providing information to the user with actionable insights.
Descriptive title Message providing information to the user with actionable insights.
Descriptive title Message that is not dismissible.
Download: 

Simple notification

Example

This example show how a MessageBar can be used to be shown as a notification (border added for styling puroses only). This example does not use the MessageBarService.

Delete operation
Successfully deleted 'XYZ-blazor.pdf'
1 hour ago
Download: 

Notification Center

Example

Copy of the button shown in the header which displays the number of notifications. Use the button in the first example to add notifications.

Download: 

MessageBar provider

Display the list of messages

You display a list of messages for a specific section using the FluentMessageBarProvider component.

<FluentMessageBarProvider Section="MESSAGE_SECTION" Format="MessageFormat.Notification" />

Documentation

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.

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.

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.

MessageOptions Class

Properties

Name
Type
Default
Description
AllowDismissbool
True
Gets or sets whether the message bar can be dismissed.
Bodystring?
Gets or sets the message to be shown in the message bar after the title.
ClearAfterNavigationbool
False
Gets or sets a value indicating whether the message will be removed after navigation.
IconIcon?
Gets or sets the icon to show in the message bar based on the intent of the message. See MessageOptions.Icon for more details.
IntentMessageIntent?
Gets or sets the intent of the message bar.
Default is MessageIntent.Info.
LinkActionLink<Message>?
Gets or sets the link to be shown in the message bar after the title/message.
OnCloseFunc<Message, Task>?
Gets or sets the action to be executed when the message bar is closed.
PrimaryActionActionButton<Message>?
Action to be executed for the primary button.
SecondaryActionActionButton<Message>?
Action to be executed for the secondary button.
Sectionstring?
Gets or sets the identification of the FluentMessageBarProvider the message belongs to.
Timeoutint?
Gets or sets the timeout in milliseconds after which the message bar is removed. Default is null.
TimestampDateTime?
Gets or sets the timestamp of the message.
Titlestring?
Gets or sets the title.
Most important info to be shown in 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
Info
Warning
Error
Success
Custom
Filled.Size20.Info
An error has occurred. This application may no longer respond until reloaded. Reload 🗙