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
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.
Timed Messages
These message automatically dismiss after a set amount of time.
MessageBar with options
Click on the button to display a message (max 5) utilizing the MessageOptions
class.
Simple messages
This example show the different intents that can be shown in a MessageBar.
This example does not use the MessageBarService
.
Simple notification
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
.
Notification Center
Copy of the button shown in the header which displays the number of notifications. Use the button in the first example to add notifications.
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 |
---|---|---|---|
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. |
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. |
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. |
MessageOptions Class
Properties
Name | Type | Default | Description |
---|---|---|---|
AllowDismiss | bool | True | Gets or sets whether the message bar can be dismissed. |
Body | string? | Gets or sets the message to be shown in the message bar after the title. | |
ClearAfterNavigation | bool | False | Gets or sets a value indicating whether the message will be removed after navigation. |
Icon | Icon? | Gets or sets the icon to show in the message bar based on the intent of the message. See MessageOptions.Icon for more details. | |
Intent | MessageIntent? | Gets or sets the intent of the message bar. Default is MessageIntent.Info. | |
Link | ActionLink<Message>? | Gets or sets the link to be shown in the message bar after the title/message. | |
OnClose | Func<Message, Task>? | Gets or sets the action to be executed when the message bar is closed. | |
PrimaryAction | ActionButton<Message>? | Action to be executed for the primary button. | |
SecondaryAction | ActionButton<Message>? | Action to be executed for the secondary button. | |
Section | string? | Gets or sets the identification of the FluentMessageBarProvider the message belongs to. | |
Timeout | int? | Gets or sets the timeout in milliseconds after which the message bar is removed. Default is null. | |
Timestamp | DateTime? | Gets or sets the timestamp of the message. | |
Title | string? | Gets or sets the title. Most important info to be shown in the message bar. |