BlazorModalDialogs 1.0.5

dotnet add package BlazorModalDialogs --version 1.0.5
                    
NuGet\Install-Package BlazorModalDialogs -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorModalDialogs" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorModalDialogs" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="BlazorModalDialogs" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorModalDialogs --version 1.0.5
                    
#r "nuget: BlazorModalDialogs, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorModalDialogs@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorModalDialogs&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=BlazorModalDialogs&version=1.0.5
                    
Install as a Cake Tool

Blazor Modal Dialogs

The Blazor Modal Dialogs library provides developers with a convenient way to create and manage modal dialogs in Blazor applications. This README file serves as a guide to help you understand the key features and usage of the library.

Features

  • Flexible Dialog Creation: Easily create and customize modal dialogs by defining the dialog content, style, buttons, and other properties to suit your application's needs.

  • Modal Dialog Stack: The library maintains a stack of modal dialogs, allowing you to show multiple dialogs sequentially. Each dialog can be independently managed, ensuring a smooth user experience.

Installation

To install Blazor Modal Dialogs, follow these steps:

  1. Open your Blazor application project.

  2. Install the package from NuGet by running the following command in the Package Manager Console:

    Install-Package BlazorModalDialogs
    

    Alternatively, you can use the NuGet Package Manager in Visual Studio to search for and install the package.

  3. Once the package is installed, you can start using the library in your Blazor components.

Usage

To utilize Blazor Modal Dialogs in your application, follow these steps:

  1. Add the necessary using statements to the _Imports.razor file:

    @using BlazorModalDialogs
    @using BlazorModalDialogs.Components // Optional, if you want to use pre-made components
    
  2. Add styles to the index.html file:

    <link href="_content/BlazorModalDialogs/css/styles.css" rel="stylesheet" />
    
  3. Use AddModalDialogs in dependency injection (DI) in your application's Startup.cs or Program.cs file. Modal dialog classes - classes of your modal windows, which will be automatically added to the markup when you use DialogProvider (see step 6 for more details):

    builder.Services.AddModalDialogs([Modal dialogs classes, like: typeof(...), typeof(...), ...]);
    
  4. In your Blazor component, inject the DialogsService:

    @inject DialogsService dialogsService
    
  5. Use the DialogsService to show a modal dialog:

    {ResultType} someResult = await dialogsService.Show<{DialogClass}, {DialogParamsClass}, {ResultType}>(new {DialogParamsClass} { ... });
    
  6. Optional: If you want to use the automatic addition of modal windows, add the DialogProvider component to MainLayout. If you don't want to use this option, just place your modal windows in the markup where you want (example Dialog Example).

    @inherits LayoutComponentBase
    
    <div class="page">
        <div class="sidebar">
            <NavMenu />
        </div>
    
        <main>
            <div class="top-row px-4">
                <a href="/" target="_blank">About</a>
            </div>
    
            <article class="content px-4">
                @Body
            </article>
        </main>
    </div>
    <DialogProvider />
    

Dialog Example

Here's an example of an InputDialog:

Specify parameters for InputDialog:

public class InputDialogParameters
{
    public string Title { get; set; }
}

Specify the InputDialog layout:

@inherits Dialog<InputDialogParameters, string>

<DialogLayout IsDisplayed="IsDisplayed">
    <Modal Title="@Params.Title" OnClose="

() => this.Cancel()" DisplayCenter="true" OnKeyEnterPressed="OnKeyEnterPressed">
        <Content>
            <input type="text" class="form-control mt-2" @bind-value="Value" @bind-value:event="oninput" />
        </Content>
        <Footer>
            <div class="mt-3">
                <ModalButton class="btn-outline-danger" OnClick="() => this.Cancel()">Cancel</ModalButton>
                <ModalButton class="btn-outline-success" OnClick="() => this.Close(Value)">Ok</ModalButton>
            </div>
        </Footer>
    </Modal>
</DialogLayout>

@code {
    protected string Value { get; set; }

    protected override void OnAfterShow()
    {
        Value = "";
        StateHasChanged();
    }

    protected void OnKeyEnterPressed()
    {
        this.Close(Value);
    }
}

Create DialogsRegistrationForm

@using <...>.InputDialog;

<InputDialog/>

Put DialogsRegistrationForm in MainLayout

@inherits LayoutComponentBase

<div class="page">
	<div class="sidebar">
		<NavMenu />
	</div>

	<main>
		<div class="top-row px-2">
			
		</div>

		<article>
			@Body
		</article>
	</main>
</div>
<DialogsRegistrationForm />

You can then:

  • Show the dialog and get the input result:

    var result = await dialogsService.Show<InputDialog, InputDialogParameters, string>(new InputDialogParameters { Title = "Some title" });
    
  • Close the dialog:

    await dialogsService.Hide<InputDialog, InputDialogParameters, string>();
    
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 316 6/28/2023