DialogService Class

Class DialogService. Contains various methods with options to open and close dialogs. Should be added as scoped service in the application services and RadzenDialog should be added in application main layout.

Inheritance

Object

DialogService

Namespace: Radzen

Assembly: Radzen.Blazor.dll

Syntax

public class DialogService

Examples

@inject DialogService DialogService
<RadzenButton Text="Show dialog with inline Blazor content" Click=@ShowInlineDialog />
@code {
 async Task ShowInlineDialog()
 {
   var result = await DialogService.OpenAsync("Simple Dialog", ds =>
     @<div>
         <p Style="margin-bottom: 1rem">Confirm?</p>
         <div class="row">
             <div class="col-md-12">
                 <RadzenButton Text="Ok" Click="() => ds.Close(true)" Style="margin-bottom: 10px; width: 150px" />
                 <RadzenButton Text="Cancel" Click="() => ds.Close(false)" ButtonStyle="ButtonStyle.Base"  Style="margin-bottom: 10px; width: 150px"/>
                 <RadzenButton Text="Refresh" Click="(() => { orderID = 10249; ds.Refresh(); })" ButtonStyle="ButtonStyle.Info"  Style="margin-bottom: 10px; width: 150px"/>
                 Order ID: @orderID
             </div>
         </div>
     </div>);
   Console.WriteLine($"Dialog result: {result}");
 }
}

Constructors

DialogServiceLink to this section

Initializes a new instance of the DialogService class.

Declaration
public DialogService(NavigationManager uriHelper, Microsoft.JSInterop.IJSRuntime jsRuntime)
Parameters
Type Name Description
NavigationManager uriHelper The URI helper.
Microsoft.JSInterop.IJSRuntime jsRuntime IJSRuntime instance.

Fields

dialogsLink to this section

The dialogs

Declaration
protected List<DialogOptions> dialogs

tasksLink to this section

The tasks

Declaration
protected List<TaskCompletionSource<object>> tasks

Methods

AlertLink to this section

Displays a alert dialog.

Declaration
public virtual Task<bool?> Alert(string message, string title, AlertOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
string message The message displayed to the user.
string title The text displayed in the title bar of the dialog.
AlertOptions options The options.
Threading.CancellationToken? cancellationToken The cancellation token.
Returns
Type Description
Task<bool?>true if the user clicked the OK button, false otherwise.

AlertLink to this section

Displays a alert dialog.

Declaration
public virtual Task<bool?> Alert(RenderFragment message, string title, AlertOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
RenderFragment message The message displayed to the user.
string title The text displayed in the title bar of the dialog.
AlertOptions options The options.
Threading.CancellationToken? cancellationToken The cancellation token.
Returns
Type Description
Task<bool?>true if the user clicked the OK button, false otherwise.

CloseLink to this section

Closes the side dialog

Declaration
public virtual void Close(object result)
Parameters
Type Name Description
object result The result of the Dialog

CloseSideLink to this section

Closes the side dialog

Declaration
public virtual void CloseSide(object result)
Parameters
Type Name Description
object result The result of the Dialog

CloseSideAsyncLink to this section

Closes the side dialog and waits for the closing animation to finish.

Declaration
public Task CloseSideAsync(object result)
Parameters
Type Name Description
object result The result of the Dialog
Returns
Type Description
Task

ConfirmLink to this section

Displays a confirmation dialog.

Declaration
public virtual Task<bool?> Confirm(string message, string title, ConfirmOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
string message The message displayed to the user.
string title The text displayed in the title bar of the dialog.
ConfirmOptions options The options.
Threading.CancellationToken? cancellationToken The cancellation token.
Returns
Type Description
Task<bool?>true if the user clicked the OK button, false otherwise.

ConfirmLink to this section

Displays a confirmation dialog.

Declaration
public virtual Task<bool?> Confirm(RenderFragment message, string title, ConfirmOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
RenderFragment message The message displayed to the user.
string title The text displayed in the title bar of the dialog.
ConfirmOptions options The options.
Threading.CancellationToken? cancellationToken The cancellation token.
Returns
Type Description
Task<bool?>true if the user clicked the OK button, false otherwise.

DisposeLink to this section

Declaration
public void Dispose()

OpenLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual void Open(string title, Dictionary<string, object> parameters, DialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
Dictionary<string, object> parameters The dialog parameters.
DialogOptions options The dialog options.

OpenLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual void Open(string title, Type componentType, Dictionary<string, object> parameters, DialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
Type componentType
Dictionary<string, object> parameters The dialog parameters.
DialogOptions options The dialog options.

OpenLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual void Open(string title, RenderFragment<DialogService> childContent, DialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
RenderFragment<DialogService> childContent
DialogOptions options The dialog options.

OpenAsyncLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual Task<object> OpenAsync(string title, Dictionary<string, object> parameters, DialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T.
DialogOptions options The dialog options.
Returns
Type Description
Task<object>The value passed as argument to Object).

OpenAsyncLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual Task<object> OpenAsync(string title, Type componentType, Dictionary<string, object> parameters, DialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
Type componentType
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T.
DialogOptions options The dialog options.
Returns
Type Description
Task<object>The value passed as argument to Object).

OpenAsyncLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual Task<object> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
string title The text displayed in the title bar of the dialog.
RenderFragment<DialogService> childContent
DialogOptions options The dialog options.
Threading.CancellationToken? cancellationToken
Returns
Type Description
Task<object>The value passed as argument to Object).

OpenAsyncLink to this section

Opens a dialog with the specified arguments.

Declaration
public virtual Task<object> OpenAsync(RenderFragment<DialogService> titleContent, RenderFragment<DialogService> childContent, DialogOptions options, Threading.CancellationToken? cancellationToken)
Parameters
Type Name Description
RenderFragment<DialogService> titleContent
RenderFragment<DialogService> childContent
DialogOptions options The dialog options.
Threading.CancellationToken? cancellationToken
Returns
Type Description
Task<object>The value passed as argument to Object).

OpenSideLink to this section

Opens a side dialog with the specified arguments

Declaration
public void OpenSide(string title, Dictionary<string, object> parameters, SideDialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the side dialog.
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T
SideDialogOptions options The side dialog options.

OpenSideLink to this section

Opens a side dialog with the specified arguments

Declaration
public void OpenSide(string title, Type componentType, Dictionary<string, object> parameters, SideDialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the side dialog.
Type componentType
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T
SideDialogOptions options The side dialog options.

OpenSideAsyncLink to this section

Opens a side dialog with the specified arguments

Declaration
public Task<object> OpenSideAsync(string title, Dictionary<string, object> parameters, SideDialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the side dialog.
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T
SideDialogOptions options The side dialog options.
Returns
Type Description
Task<object>A task that completes when the dialog is closed or a new one opened

OpenSideAsyncLink to this section

Opens a side dialog with the specified arguments

Declaration
public Task<object> OpenSideAsync(string title, Type componentType, Dictionary<string, object> parameters, SideDialogOptions options)
Parameters
Type Name Description
string title The text displayed in the title bar of the side dialog.
Type componentType
Dictionary<string, object> parameters The dialog parameters. Passed as property values of T
SideDialogOptions options The side dialog options.
Returns
Type Description
Task<object>A task that completes when the dialog is closed or a new one opened

RefreshLink to this section

Invokes OnRefresh.

Declaration
public void Refresh()

TryCloseAsyncLink to this section

Attempts to close the last opened dialog. Invokes CanClose if set.

Declaration
public virtual Task<bool> TryCloseAsync(object result)
Parameters
Type Name Description
object result The result.
Returns
Type Description
Task<bool>true if the dialog was closed; false if closing was prevented by CanClose.

TryCloseFromJsLink to this section

Attempts to close the last opened dialog. Called from JavaScript ESC handler.

Declaration
public virtual Task<bool> TryCloseFromJs(object result)
Parameters
Type Name Description
object result The result.
Returns
Type Description
Task<bool>true if the dialog was closed; false if closing was prevented.

TryCloseSideAsyncLink to this section

Attempts to close the side dialog. Invokes CanClose if set.

Declaration
public virtual Task<bool> TryCloseSideAsync(object result)
Parameters
Type Name Description
object result The result.
Returns
Type Description
Task<bool>true if the side dialog was closed; false if closing was prevented by CanClose.

TryCloseSideFromJsLink to this section

Attempts to close the side dialog. Called from JavaScript ESC handler.

Declaration
public virtual Task<bool> TryCloseSideFromJs(object result)
Parameters
Type Name Description
object result The result.
Returns
Type Description
Task<bool>true if the side dialog was closed; false if closing was prevented.

Events

OnCloseLink to this section

Raises the Close event.

Declaration
public event Action<object> OnClose

OnOpenLink to this section

Occurs when a new dialog is open.

Declaration
public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen

OnRefreshLink to this section

Occurs when [on refresh].

Declaration
public event Action OnRefresh

OnSideCloseLink to this section

Raises the Close event for the side dialog

Declaration
public event Action<object> OnSideClose

OnSideOpenLink to this section

Raises the Open event for the side dialog

Declaration
public event Action<Type, Dictionary<string, object>, SideDialogOptions> OnSideOpen
An error has occurred. This app may no longer respond until reloaded. Reload 🗙