(Blazor)为什么儿童剃须刀组件不工作



我正在尝试将子组件包含到父组件中

但是子组件不工作

以下是代码

==================== parent component razor ====================
<InfoDialog @ref="infoDialog"></InfoDialog>
==================== parent component code behind ====================
public InfoDialog infoDialog { get; set; }
public async Task AddToDB()
{
infoDialog.Show("success", "request complete!");
}
==================== child component razor ====================
<MatDialog @bind-IsOpen="@IsShow">
<MatDialogTitle>@Title</MatDialogTitle>
<MatDialogContent>
<p>@Description</p>
</MatDialogContent>
<MatDialogActions>
<MatButton OnClick="@Close">OK</MatButton>
</MatDialogActions>
</MatDialog>
==================== child component code behind ====================
public partial class InfoDialog
{
public bool IsShow { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public void Show(string _title, string _Description)
{
IsShow = true;
Title = _title;
Description = _Description;
}
public void Close()
{
IsShow = false;
}
}

当我调用"AddToDB"函数时,我调用了子组件的show函数,但没有呈现子组件。有人能帮我吗?

抱歉我的英语不好

尝试在子组件方法中调用StateHasChanged()

public void Show(string _title, string _Description)
{
IsShow = true;
Title = _title;
Description = _Description;
StateHasChanged();
}
public void Close()
{
IsShow = false;
StateHasChanged();
}

最新更新