Deprecated Sorry guys, no maintenance. This library is deprecated.
A Blazor wrapper of Window.confirm() and onbeforeunload confirmation as .Net Blazor Component.
The sample project has been published here.
Note: Just as Blazor, this repo is also experimental.
Remember:
... but in some cases we need them.
Because we love screen shots and demos.
Demo: https://ctrl-alt-d.github.io/BlazorConfirm/
-
0.7.0.1
- Migrated to Blazor 0.7.0 experimental.
-
0.6.0.1
- Handling onbeforeunload
-
version 0.6.0
- initial version for blazor 0.6.0
dotnet add package BlazorConfirm --version 0.7.0.1
Or:
Install-Package BlazorConfirm -Version 0.7.0.1
Set DI on ConfigureServices
of your Startup.cs
:
using ctrlaltd.SimpleBlazorComponents;
using Microsoft.AspNetCore.Blazor.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace Sample
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSingleton<IBlazorConfirmDialog, BlazorConfirmDialog>(); //Add as singleton.
}
and add the component to App.cshtml
(or to another component always loaded in the application)
@addTagHelper *, BlazorConfirm
<BlazorConfirmContainer />
<Router AppAssembly=typeof(Program).Assembly />
In a component:
@inject ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog
In a class:
[Inject]
protected ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog { get; set; }
At this point you can wrap your code into the onSuccessDelegate
Dialog:
void IncrementCount()
{
blazorConfirmDialog.NewDialog( message: "Are you sure do you want to increment the counter?",
onSuccessDelegate: ( () => {currentCount++;
StateHasChanged();
} ) );
}
A sample to confirm exit current page:
blazorConfirmDialog.NewDialog( onSuccessDelegate: (() => {UriHelper.NavigateTo( "/fetchdata" );}));
Dani Herrera
BlazorConfirm is licensed under MIT license
Thankyou to @ghidello and https://github.com/sotsera/sotsera.blazor.toaster repo.