【发布时间】:2020-11-04 06:40:03
【问题描述】:
我使用 Syncfusion 创建了一个 Dialog 组件,我试图从父组件调用它,但它没有呈现。
这是我的父组件,我在我的子组件(ModalAcceptCancel)中使用@ref,所以当我单击删除按钮(在我的网格中)时,我能够调用一个名为 OpenDialog 的方法来呈现或显示我的模态。
@using App.Dtos
@using App.Data
@using Syncfusion.Blazor.Buttons
@inject NavigationManager NavigationManager
//This is my child component
<ModalAcceptCancel @ref="Modal"/>
//
<SfGrid @ref="SfGridProfesores" DataSource="@DsProfesores" AllowPaging="true">
<GridColumns>
<GridColumn Field=@nameof(ProfesorDto.Id) HeaderText="Identificador" TextAlign="TextAlign.Right" Width="120">
</GridColumn>
<GridColumn Field=@nameof(ProfesorDto.Nombres) HeaderText="Nombre" Width="200"></GridColumn>
<GridColumn Field=@nameof(ProfesorDto.CorreoElectronico) HeaderText="Correo Electrónico" Width="150"></GridColumn>
<GridColumn HeaderText="Acciones" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
var profesor = (context as ProfesorDto);
<SfButton @onclick="@(() => NavigationManager.NavigateTo("Profesor/"+profesor.Id))" CssClass="e-info">Editar</SfButton>
<SfButton CssClass="e-danger" @onclick="(() => DeleteProfesor(profesor.Id))">Borrar</SfButton>
}
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
@code {
[Parameter]
public IReadOnlyList<ProfesorDto> DsProfesores { get; set; }
[Inject]
public IProfesorService ProfesorService { get; set; }
SfGrid<ProfesorDto> SfGridProfesores;
ModalAcceptCancel Modal;
//Here i try to open my Modal (ChildComponent)
private void DeleteProfesor(int id)
{
Modal.OpenDialog();
//ProfesorService.BorraProfesor(id);
// SfGridProfesores.Refresh();
}
}
这是来自我的子组件的代码。我的 Syncfusion 对话框可见性绑定到“Is Visible 属性”,当调用 OpenDialog 方法时,该属性更改为 true,它应该显示我的模式。
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
<SfDialog Width="500px" ShowCloseIcon="true" CloseOnEscape="true" @bind-Visible="@IsVisible">
<DialogTemplates>
<Header> Atención </Header>
<Content> ¿Estás seguro que deseas eliminar este elemento? </Content>
<FooterTemplate>
<SfButton CssClass="e-primary e-flat" @onclick="@CloseDialog">
Aceptar
</SfButton>
<SfButton CssClass="e-flat" @onclick="@CloseDialog">
Cancelar
</SfButton>
</FooterTemplate>
</DialogTemplates>
</SfDialog>
@code {
private bool IsVisible { get; set; } = false;
public void OpenDialog()
{
this.IsVisible = true;
}
public void CloseDialog()
{
this.IsVisible = false;
}
}
¿我做错了什么? ¿ 这样做有更好的做法吗?
我对开发真的很陌生。对不起我的英语。
【问题讨论】:
标签: render blazor syncfusion