Class DialogService
- Namespace
- Radzen
- Assembly
- Radzen.Blazor.dll
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.
public class DialogService : IDisposable
- Inheritance
-
DialogService
- Implements
- Inherited Members
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.
public DialogService(NavigationManager uriHelper, IJSRuntime jsRuntime)
Parameters
uriHelper
NavigationManagerThe URI helper.
jsRuntime
IJSRuntimeIJSRuntime instance.
Fields
dialogs
The dialogs
protected List<object> dialogs
Field Value
tasks
The tasks
protected List<TaskCompletionSource<dynamic>> tasks
Field Value
- List<TaskCompletionSource<dynamic>>
Methods
Alert(string, string, AlertOptions)
Displays a alert dialog.
public virtual Task<bool?> Alert(string message = "", string title = "Message", AlertOptions options = null)
Parameters
message
stringThe message displayed to the user.
title
stringThe text displayed in the title bar of the dialog.
options
AlertOptionsThe options.
Returns
Close(dynamic)
Closes the last opened dialog with optional result.
[JSInvokable("DialogService.Close")]
public virtual void Close(dynamic result = null)
Parameters
result
dynamicThe result.
CloseSide(dynamic)
Closes the side dialog
public void CloseSide(dynamic result = null)
Parameters
result
dynamicThe result of the Dialog
Confirm(string, string, ConfirmOptions)
Displays a confirmation dialog.
public virtual Task<bool?> Confirm(string message = "Confirm?", string title = "Confirm", ConfirmOptions options = null)
Parameters
message
stringThe message displayed to the user.
title
stringThe text displayed in the title bar of the dialog.
options
ConfirmOptionsThe options.
Returns
Dispose()
public void Dispose()
Open(string, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
public virtual void Open(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)
Parameters
title
stringThe text displayed in the title bar of the dialog.
childContent
RenderFragment<DialogService>The content displayed in the dialog.
options
DialogOptionsThe dialog options.
OpenAsync(RenderFragment<DialogService>, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
public virtual Task<dynamic> OpenAsync(RenderFragment<DialogService> titleContent, RenderFragment<DialogService> childContent, DialogOptions options = null)
Parameters
titleContent
RenderFragment<DialogService>The content displayed in the title bar of the dialog.
childContent
RenderFragment<DialogService>The content displayed in the dialog.
options
DialogOptionsThe dialog options.
Returns
- Task<dynamic>
The value passed as argument to Close(dynamic).
OpenAsync(string, RenderFragment<DialogService>, DialogOptions)
Opens a dialog with the specified content.
public virtual Task<dynamic> OpenAsync(string title, RenderFragment<DialogService> childContent, DialogOptions options = null)
Parameters
title
stringThe text displayed in the title bar of the dialog.
childContent
RenderFragment<DialogService>The content displayed in the dialog.
options
DialogOptionsThe dialog options.
Returns
- Task<dynamic>
The value passed as argument to Close(dynamic).
OpenAsync<T>(string, Dictionary<string, object>, DialogOptions)
Opens a dialog with the specified arguments.
public virtual Task<dynamic> OpenAsync<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase
Parameters
title
stringThe text displayed in the title bar of the dialog.
parameters
Dictionary<string, object>The dialog parameters. Passed as property values of
T
.options
DialogOptionsThe dialog options.
Returns
- Task<dynamic>
The value passed as argument to Close(dynamic).
Type Parameters
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
public Task<dynamic> OpenSideAsync<T>(string title, Dictionary<string, object> parameters = null, SideDialogOptions options = null) where T : ComponentBase
Parameters
title
stringThe text displayed in the title bar of the side dialog.
parameters
Dictionary<string, object>The dialog parameters. Passed as property values of
T
options
SideDialogOptionsThe side dialog options.
Returns
- Task<dynamic>
A task that completes when the dialog is closed or a new one opened
Type Parameters
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.
public virtual void Open<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null) where T : ComponentBase
Parameters
title
stringThe text displayed in the title bar of the dialog.
parameters
Dictionary<string, object>The dialog parameters. Passed as property values of
T
.options
DialogOptionsThe dialog options.
Type Parameters
T
The type of the Blazor component which will be displayed in a dialog.
Refresh()
Invokes OnRefresh.
public void Refresh()
Events
OnClose
Raises the Close event.
public event Action<dynamic> OnClose
Event Type
- Action<dynamic>
OnOpen
Occurs when a new dialog is open.
public event Action<string, Type, Dictionary<string, object>, DialogOptions> OnOpen
Event Type
OnRefresh
Occurs when [on refresh].
public event Action OnRefresh
Event Type
OnSideClose
Raises the Close event for the side dialog
public event Action<dynamic> OnSideClose
Event Type
- Action<dynamic>
OnSideOpen
Raises the Open event for the side dialog
public event Action<Type, Dictionary<string, object>, SideDialogOptions> OnSideOpen