Class TooltipService
A service for displaying tooltips programmatically on UI elements or at specific positions. TooltipService provides methods to show tooltips with text or custom HTML content, with configurable positioning, delays, and durations. To use this service, add it as a scoped service in your application's service collection and place a RadzenTooltip component in your main layout. Manages tooltip lifecycle, automatically closing tooltips on navigation and providing various positioning options (top, bottom, left, right). Tooltips can be shown on mouse enter/leave events or on demand, with configurable delays before showing and auto-close durations.
Implements
Inherited Members
Namespace: Radzen
Assembly: Radzen.Blazor.dll
Syntax
public class TooltipService : IDisposable
Examples
Show a simple text tooltip:
@inject TooltipService TooltipService
<RadzenButton Text="Hover me" MouseEnter="@(args => TooltipService.Open(args, "This is a tooltip"))" />
Show a tooltip with HTML content and custom options:
@inject TooltipService TooltipService
<RadzenButton Text="Show tooltip" MouseEnter="@(args => ShowTooltipWithHtml(args))" />
@code {
void ShowTooltipWithHtml(ElementReference element) => TooltipService.Open(element, ts =>
@<div>
<b>Bold</b> and <i>italic</i> content
</div>,
new TooltipOptions { Position = TooltipPosition.Top, Duration = 5000 });
}
Constructors
TooltipService(NavigationManager)
Initializes a new instance of the TooltipService class.
Declaration
public TooltipService(NavigationManager uriHelper)
Parameters
| Type | Name | Description |
|---|---|---|
| NavigationManager | uriHelper | The URI helper. |
Methods
Close()
Closes this instance.
Declaration
public void Close()
Dispose()
Disposes this instance.
Declaration
public void Dispose()
Open(ElementReference, RenderFragment<TooltipService>, TooltipOptions)
Opens a tooltip with custom HTML content near the specified element. The tooltip will be positioned according to the options and can contain any Blazor markup.
Declaration
public void Open(ElementReference element, RenderFragment<TooltipService> childContent, TooltipOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The HTML element reference near which the tooltip will be displayed. |
| RenderFragment<TooltipService> | childContent | A render fragment that defines the custom HTML content of the tooltip. Receives the TooltipService as context. |
| TooltipOptions | options | Optional tooltip configuration including position, duration, delay, and styling. If null, default options are used. |
Open(ElementReference, string, TooltipOptions)
Opens a tooltip with simple text content near the specified element. This is the most common way to show basic informational tooltips.
Declaration
public void Open(ElementReference element, string text, TooltipOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The HTML element reference near which the tooltip will be displayed. |
| string | text | The text content to display in the tooltip. |
| TooltipOptions | options | Optional tooltip configuration including position, duration, delay, and styling. If null, default options are used. |
OpenOnTheBottom(ElementReference, string, TooltipOptions)
Opens the specified element on the bottom position.
Declaration
public void OpenOnTheBottom(ElementReference element, string text, TooltipOptions o = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The element. |
| string | text | The text. |
| TooltipOptions | o | The o. |
OpenOnTheLeft(ElementReference, string, TooltipOptions)
Opens the specified element on the left position.
Declaration
public void OpenOnTheLeft(ElementReference element, string text, TooltipOptions o = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The element. |
| string | text | The text. |
| TooltipOptions | o | The o. |
OpenOnTheRight(ElementReference, string, TooltipOptions)
Opens the specified element on the right position.
Declaration
public void OpenOnTheRight(ElementReference element, string text, TooltipOptions o = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The element. |
| string | text | The text. |
| TooltipOptions | o | The o. |
OpenOnTheTop(ElementReference, string, TooltipOptions)
Opens a tooltip with text content positioned above the specified element. This is a convenience method equivalent to calling Open() with TooltipPosition.Top.
Declaration
public void OpenOnTheTop(ElementReference element, string text, TooltipOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ElementReference | element | The HTML element reference above which the tooltip will be displayed. |
| string | text | The text content to display in the tooltip. |
| TooltipOptions | options | Optional additional tooltip configuration. The Position will be set to Top regardless of the value in options. |
Events
OnClose
Raises the Close event.
Declaration
public event Action OnClose
Event Type
| Type | Description |
|---|---|
| Action |
OnNavigate
Occurs when [on navigate].
Declaration
public event Action OnNavigate
Event Type
| Type | Description |
|---|---|
| Action |
OnOpen
Occurs when [on open].
Declaration
public event Action<ElementReference, Type, TooltipOptions> OnOpen
Event Type
| Type | Description |
|---|---|
| Action<ElementReference, Type, TooltipOptions> |