Class DialogService
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.
Implements
Inherited Members
Namespace: Radzen
Assembly: Radzen.Blazor.dll
Syntax
public class DialogService : IDisposable
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
DialogService(NavigationManager, IJSRuntime)
Initializes a new instance of the DialogService class.
Declaration
public DialogService(NavigationManager uriHelper, IJSRuntime jsRuntime)
Parameters
| Type | Name | Description |
|---|---|---|
| NavigationManager | uriHelper | The URI helper. |
| IJSRuntime | jsRuntime | IJSRuntime instance. |
Fields
dialogs
The dialogs
Declaration
protected List<object> dialogs
Field Value
| Type | Description |
|---|---|
| List<object> |
tasks
The tasks
Declaration
protected List<TaskCompletionSource<dynamic>> tasks
Field Value
| Type | Description |
|---|---|
| List<TaskCompletionSource<dynamic>> |
Methods
Alert(RenderFragment, string, AlertOptions, CancellationToken?)
Displays a alert dialog.
Declaration
public virtual Task<bool?> Alert(RenderFragment message, string title = "Message", AlertOptions options = null, CancellationToken? cancellationToken = null)
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. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool?> |
|
Alert(string, string, AlertOptions, CancellationToken?)
Displays a alert dialog.
Declaration
public virtual Task<bool?> Alert(string message = "", string title = "Message", AlertOptions options = null, CancellationToken? cancellationToken = null)
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. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool?> |
|
Close(dynamic)
Closes the last opened dialog with optional result.
Declaration
[JSInvokable("DialogService.Close")]
public virtual void Close(dynamic result = null)
Parameters
| Type | Name | Description |
|---|---|---|
| dynamic | result | The result. |
CloseSide(dynamic)
Closes the side dialog
Declaration
public void CloseSide(dynamic result = null)
Parameters
| Type | Name | Description |
|---|---|---|
| dynamic | result | The result of the Dialog |
CloseSideAsync(dynamic)
Closes the side dialog and waits for the closing animation to finish.
Declaration
public Task CloseSideAsync(dynamic result = null)
Parameters
| Type | Name | Description |
|---|---|---|
| dynamic | result | The result of the Dialog |
Returns
| Type | Description |
|---|---|
| Task |
Confirm(RenderFragment, string, ConfirmOptions, CancellationToken?)
Displays a confirmation dialog.
Declaration
public virtual Task<bool?> Confirm(RenderFragment message, string title = "Confirm", ConfirmOptions options = null, CancellationToken? cancellationToken = null)
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. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool?> |
|
Confirm(string, string, ConfirmOptions, CancellationToken?)
Displays a confirmation dialog.
Declaration
public virtual Task<bool?> Confirm(string message = "Confirm?", string title = "Confirm", ConfirmOptions options = null, CancellationToken? cancellationToken = null)
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. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool?> |
|
Dispose()
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.
Declaration
public void Dispose()
Open(string, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
Declaration
public virtual void Open(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the dialog. |
| RenderFragment<DialogService> | childContent | The content displayed in the dialog. |
| DialogOptions | options | The dialog options. |
Open(string, Type, Dictionary<string, object>, DialogOptions)
Opens a dialog with the specified arguments.
Declaration
public virtual void Open(string title, Type componentType, Dictionary<string, object> parameters = null, DialogOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the dialog. |
| Type | componentType | The type of the component to be displayed in the dialog. Must inherit from ComponentBase. |
| Dictionary<string, object> | parameters | The dialog parameters. |
| DialogOptions | options | The dialog options. |
OpenAsync(RenderFragment<DialogService>, RenderFragment<DialogService>, DialogOptions, CancellationToken?)
Opens a dialog with the specified content.
Declaration
public virtual Task<dynamic> OpenAsync(RenderFragment<DialogService> titleContent, RenderFragment<DialogService> childContent, DialogOptions options = null, CancellationToken? cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RenderFragment<DialogService> | titleContent | The content displayed in the title bar of the dialog. |
| RenderFragment<DialogService> | childContent | The content displayed in the dialog. |
| DialogOptions | options | The dialog options. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | The value passed as argument to Close(dynamic). |
OpenAsync(string, RenderFragment<DialogService>, DialogOptions, CancellationToken?)
Opens a dialog with the specified content.
Declaration
public virtual Task<dynamic> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options = null, CancellationToken? cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the dialog. |
| RenderFragment<DialogService> | childContent | The content displayed in the dialog. |
| DialogOptions | options | The dialog options. |
| CancellationToken? | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | The value passed as argument to Close(dynamic). |
OpenAsync(string, Type, Dictionary<string, object>, DialogOptions)
Opens a dialog with the specified arguments dynamically.
Declaration
public virtual Task<dynamic> OpenAsync(string title, Type componentType, Dictionary<string, object> parameters = null, DialogOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the dialog. |
| Type | componentType | The type of the Blazor component to be displayed in a dialog. Must inherit from ComponentBase. |
| Dictionary<string, object> | parameters | The dialog parameters, passed as property values of the specified component. |
| DialogOptions | options | The dialog options. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | A task that represents the result passed as an argument to Close(dynamic). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
OpenAsync<T>(string, Dictionary<string, object>, DialogOptions)
Opens a dialog with the specified arguments.
Declaration
public virtual Task<dynamic> OpenAsync<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase
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 |
| DialogOptions | options | The dialog options. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | The value passed as argument to Close(dynamic). |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the Blazor component which will be displayed in a dialog. |
OpenSide(string, Type, Dictionary<string, object>, SideDialogOptions)
Opens a side dialog with the specified arguments dynamically.
Declaration
public void OpenSide(string title, Type componentType, Dictionary<string, object> parameters = null, SideDialogOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the side dialog. |
| Type | componentType | The type of the Blazor component to be displayed in the side dialog. Must inherit from ComponentBase. |
| Dictionary<string, object> | parameters | The dialog parameters, passed as property values of the specified component. |
| SideDialogOptions | options | The side dialog options. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
OpenSideAsync(string, Type, Dictionary<string, object>, SideDialogOptions)
Opens a side dialog with the specified arguments dynamically.
Declaration
public Task<dynamic> OpenSideAsync(string title, Type componentType, Dictionary<string, object> parameters = null, SideDialogOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | title | The text displayed in the title bar of the side dialog. |
| Type | componentType | The type of the Blazor component to be displayed in the side dialog. Must inherit from ComponentBase. |
| Dictionary<string, object> | parameters | The dialog parameters, passed as property values of the specified component. |
| SideDialogOptions | options | The side dialog options. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | A task that represents the result passed as an argument to CloseSide(dynamic). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
OpenSideAsync<T>(string, Dictionary<string, object>, SideDialogOptions)
Opens a side dialog with the specified arguments
Declaration
public Task<dynamic> OpenSideAsync<T>(string title, Dictionary<string, object> parameters = null, SideDialogOptions options = null) where T : ComponentBase
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 |
| SideDialogOptions | options | The side dialog options. |
Returns
| Type | Description |
|---|---|
| Task<dynamic> | A task that completes when the dialog is closed or a new one opened |
Type Parameters
| Name | Description |
|---|---|
| T | The type of Blazor component which will be displayed in the side dialog. |
OpenSide<T>(string, Dictionary<string, object>, SideDialogOptions)
Opens a side dialog with the specified arguments
Declaration
public void OpenSide<T>(string title, Dictionary<string, object> parameters = null, SideDialogOptions options = null) where T : ComponentBase
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 |
| SideDialogOptions | options | The side dialog options. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of Blazor component which will be displayed in the side dialog. |
Open<T>(string, Dictionary<string, object>, DialogOptions)
Opens a dialog with the specified arguments.
Declaration
public virtual void Open<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase
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. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the Blazor component which will be displayed in a dialog. |
Refresh()
Invokes OnRefresh.
Declaration
public void Refresh()
Events
OnClose
Raises the Close event.
Declaration
public event Action<dynamic> OnClose
Event Type
| Type | Description |
|---|---|
| Action<dynamic> |
OnOpen
Occurs when a new dialog is open.
Declaration
public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen
Event Type
| Type | Description |
|---|---|
| Action<string, Type, Dictionary<string, object>, DialogOptions> |
OnRefresh
Occurs when [on refresh].
Declaration
public event Action OnRefresh
Event Type
| Type | Description |
|---|---|
| Action |
OnSideClose
Raises the Close event for the side dialog
Declaration
public event Action<dynamic> OnSideClose
Event Type
| Type | Description |
|---|---|
| Action<dynamic> |
OnSideOpen
Raises the Open event for the side dialog
Declaration
public event Action<Type, Dictionary<string, object>, SideDialogOptions> OnSideOpen
Event Type
| Type | Description |
|---|---|
| Action<Type, Dictionary<string, object>, SideDialogOptions> |