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.
Inheritance
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<System.Object> |
tasks
The tasks
Declaration
protected List<TaskCompletionSource<dynamic>> tasks
Field Value
Type | Description |
---|---|
List<TaskCompletionSource<System.Object>> |
Methods
Alert(String, String, AlertOptions)
Displays a alert dialog.
Declaration
public virtual async Task<bool?> Alert(string message = "", string title = "Message", AlertOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | The message displayed to the user. |
System.String | title | The text displayed in the title bar of the dialog. |
AlertOptions | options | The options. |
Returns
Type | Description |
---|---|
Task<System.Nullable<System.Boolean>> |
|
Close(Object)
Closes the last opened dialog with optional result.
Declaration
public virtual void Close(dynamic result = null)
Parameters
Type | Name | Description |
---|---|---|
System.Object | result | The result. |
CloseSide(Object)
Closes the side dialog
Declaration
public void CloseSide(dynamic result = null)
Parameters
Type | Name | Description |
---|---|---|
System.Object | result | The result of the Dialog |
Confirm(String, String, ConfirmOptions)
Displays a confirmation dialog.
Declaration
public virtual async Task<bool?> Confirm(string message = "Confirm?", string title = "Confirm", ConfirmOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | The message displayed to the user. |
System.String | title | The text displayed in the title bar of the dialog. |
ConfirmOptions | options | The options. |
Returns
Type | Description |
---|---|
Task<System.Nullable<System.Boolean>> |
|
Dispose()
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 |
---|---|---|
System.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<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 |
---|---|---|
System.String | title | The text displayed in the title bar of the dialog. |
Dictionary<System.String, System.Object> | parameters | The dialog parameters. Passed as property values of |
DialogOptions | options | The dialog options. |
Type Parameters
Name | Description |
---|---|
T | The type of the Blazor component which will be displayed in a dialog. |
OpenAsync(RenderFragment<DialogService>, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
Declaration
public virtual Task<dynamic> OpenAsync(RenderFragment<DialogService> titleContent, RenderFragment<DialogService> childContent, DialogOptions options = 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. |
Returns
Type | Description |
---|---|
Task<System.Object> | The value passed as argument to Close(Object). |
OpenAsync(String, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
Declaration
public virtual Task<dynamic> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
System.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. |
Returns
Type | Description |
---|---|
Task<System.Object> | The value passed as argument to Close(Object). |
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 |
---|---|---|
System.String | title | The text displayed in the title bar of the dialog. |
Dictionary<System.String, System.Object> | parameters | The dialog parameters. Passed as property values of |
DialogOptions | options | The dialog options. |
Returns
Type | Description |
---|---|
Task<System.Object> | The value passed as argument to Close(Object). |
Type Parameters
Name | Description |
---|---|
T | The type of the Blazor component which will be displayed in a dialog. |
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 |
---|---|---|
System.String | title | The text displayed in the title bar of the side dialog. |
Dictionary<System.String, System.Object> | parameters | The dialog parameters. Passed as property values of |
SideDialogOptions | options | The side dialog options. |
Returns
Type | Description |
---|---|
Task<System.Object> | 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. |
Refresh()
Invokes OnRefresh.
Declaration
public void Refresh()
Events
OnClose
Raises the Close event.
Declaration
public event Action<dynamic> OnClose
Event Type
Type | Description |
---|---|
Action<System.Object> |
OnOpen
Occurs when a new dialog is open.
Declaration
public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen
Event Type
Type | Description |
---|---|
Action<System.String, Type, Dictionary<System.String, System.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<System.Object> |
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<System.String, System.Object>, SideDialogOptions> |