Class ToastTemplates
Configure templates to display within a header, content, and footer section of Toast.
Inheritance
Namespace: Syncfusion.Blazor.Notifications
Assembly: Syncfusion.Blazor.dll
Syntax
public class ToastTemplates : OwningComponentBase
Remarks
The ToastTemplates class allows you to define custom templates for different sections of toast notifications. You can customize the title, content, and overall template of toast messages to match your application's design and requirements. This component works as a child component of SfToast and provides flexible templating options.
Examples
Basic usage of ToastTemplates with custom title and content templates.
<SfToast>
<ToastTemplates>
<Title>
<div class="toast-title">Custom Title</div>
</Title>
<Content>
<div class="toast-content">
<p>Custom content with HTML elements</p>
</div>
</Content>
</ToastTemplates>
</SfToast>
Constructors
ToastTemplates()
Declaration
public ToastTemplates()
Properties
Content
Gets or sets the template for the toast content section.
Declaration
public RenderFragment Content { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.RenderFragment | A Microsoft.AspNetCore.Components.RenderFragment that defines the custom template for the toast content. The default value is |
Remarks
This property allows you to define a custom template for the main content area of toast notifications. When specified, the custom content template replaces the default content display and provides complete control over the content presentation. You can include rich HTML content, interactive elements, buttons, images, or any other Blazor components within this template.
Examples
Creating a custom content template with buttons and formatted text.
<ToastTemplates>
<Content>
<div class="custom-content">
<p>Do you want to save your changes?</p>
<button class="btn-save" onclick="saveChanges()">Save</button>
<button class="btn-discard" onclick="discardChanges()">Discard</button>
</div>
</Content>
</ToastTemplates>
Template
Gets or sets the complete template for the entire toast notification.
Declaration
public RenderFragment Template { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.RenderFragment | A Microsoft.AspNetCore.Components.RenderFragment that defines the overall template for the entire toast notification. The default value is |
Remarks
This property allows you to define a completely custom template that overrides the entire toast structure. When this template is specified, it takes precedence over both Title and Content templates, providing complete control over the toast's appearance and layout. This is useful when you need to create entirely custom toast designs that don't follow the standard title-content structure.
Examples
Defining a complete custom toast template with custom layout.
<ToastTemplates>
<Template>
<div class="custom-toast">
<div class="toast-header">
<img src="logo.png" alt="Logo" />
<h3>Custom Toast</h3>
</div>
<div class="toast-body">
<p>Complete custom toast content</p>
</div>
<div class="toast-actions">
<button>Action</button>
</div>
</div>
</Template>
</ToastTemplates>
Title
Gets or sets the template for the toast title section.
Declaration
public RenderFragment Title { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.RenderFragment | A Microsoft.AspNetCore.Components.RenderFragment that defines the custom template for the toast title. The default value is |
Remarks
This property allows you to define a custom template for the title area of toast notifications. When specified, the custom title template overrides the default title display and provides full control over the title presentation. You can include any HTML elements, Blazor components, or custom styling within this template.
Examples
Defining a custom title template with an icon and styled text.
<ToastTemplates>
<Title>
<div class="custom-title">
<i class="icon-info"></i>
<span>Important Notification</span>
</div>
</Title>
</ToastTemplates>
Methods
BuildRenderTree(RenderTreeBuilder)
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
Type | Name | Description |
---|---|---|
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder | __builder |
Dispose()
Releases all resources used by the ToastTemplates component.
Declaration
public virtual void Dispose()
Remarks
This method performs cleanup operations to free up resources and prevent memory leaks.
It calls the overloaded Dispose(Boolean) method with true
to indicate
that both managed and unmanaged resources should be disposed.
Dispose(Boolean)
Releases the unmanaged resources used by the ToastTemplates component and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | A System.Boolean value indicating whether the method was called from the Dispose() method ( |
Remarks
This method performs the actual cleanup of resources. When disposing
is true
,
both managed and unmanaged resources are released. This includes clearing references to the parent component
and child content to prevent memory leaks. The method calls the base class disposal method to ensure
proper cleanup of inherited resources.
OnInitializedAsync()
Method invoked when the component is ready to start.
Declaration
protected override Task OnInitializedAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.Task representing any asynchronous operation. |