BlazorBootstrapToasts 1.0.3
dotnet add package BlazorBootstrapToasts --version 1.0.3
NuGet\Install-Package BlazorBootstrapToasts -Version 1.0.3
<PackageReference Include="BlazorBootstrapToasts" Version="1.0.3" />
<PackageVersion Include="BlazorBootstrapToasts" Version="1.0.3" />
<PackageReference Include="BlazorBootstrapToasts" />
paket add BlazorBootstrapToasts --version 1.0.3
#r "nuget: BlazorBootstrapToasts, 1.0.3"
#:package BlazorBootstrapToasts@1.0.3
#addin nuget:?package=BlazorBootstrapToasts&version=1.0.3
#tool nuget:?package=BlazorBootstrapToasts&version=1.0.3
blazor-bootstrap-toasts
Easy to use toast component based on bootstrap alerts. Only C# and CSS. No Javascript.
demo: http://toasts.kruki.at/ source code and working example code: https://gitlab.com/tkruk34/blazor-bootstrap-toasts
how to use
There are 2 possibilities how to use blazor-bootstrap-toasts.
use as single component
To use the toast component just insert the toast component like this:
<Toast @ref="Toast"></Toast>
Then add a reference to the toast in the @code-section like this:
public Toast Toast { get; set; }
Now you can call the from whereever you want in the scope like this:
Toast.Show("success","my message bla bla...",3000)
use a singleton (as service)
First of all you have to register the included service in your program.cs like this:
program.cs
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<IToastService, ToastService>();
await builder.Build().RunAsync();
}
Then you have to add a toast component to the service. To use the Service in your whole application, just add it in the app.razor component.
@using BlazorBootstrapToasts
@inject IToastService ToastService
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<Toast @ref="Toast"></Toast>
@code{
private Toast Toast { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
ToastService.RegisterComponent(Toast);
}
}
}
Now you can inject the service whereever you want and call the Show()-method on the service.
<button class="btn btn-block btn-success" onclick="@(() => {ToastService.Show("success", Message, Duration); })">Success</button>
use custom item template
<Toast @ref="Toast">
<ToastContent Context="message">
My message in the custom toast: <b>@message</b>
</ToastContent>
</Toast>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net5.0
- Microsoft.AspNetCore.Components.Web (>= 5.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.