Kok*_*_rs 6 .net c# blazor mudblazor
我在 Blazor 应用程序中使用 Mudblazor。以下代码打开一个对话框:
private async Task OpenDialog()
{
var options = new DialogOptions { CloseOnEscapeKey = true };
var dialog = DialogService.Show<AddNewAppDialog>("Adding new application", options);
// TODO refresh data on dialog close
}
Run Code Online (Sandbox Code Playgroud)
AddNewAppDialog 组件的代码非常简单:
<MudDialog>
<DialogContent>
<MudTextField @bind-Value="ApplicationName" Variant="Variant.Outlined" Label="Application Name" />
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
</DialogActions>
Run Code Online (Sandbox Code Playgroud)
@code {
public string ApplicationName { get; set; }
[CascadingParameter]
MudDialogInstance MudDialog { get; set; }
async Task Submit()
{
await CreateApplication();
MudDialog.Close(DialogResult.Ok(true));
}
void Cancel() => MudDialog.Cancel();
}
Run Code Online (Sandbox Code Playgroud)
当我的对话框关闭时,如何在父组件中获取事件?
你必须使用await dialog.Result;:
private async Task OpenDialog()
{
var options = new DialogOptions { CloseOnEscapeKey = true };
var dialog = DialogService.Show<AddNewAppDialog>("Adding new application", options);
// wait modal to close
var result = await dialog.Result;
// you can check if the modal was cancelled
var isCancelled = result.Cancelled;
// refresh your data
}
Run Code Online (Sandbox Code Playgroud)
https://mudblazor.com/components/dialog#passing-data