(Blazor) 为什么儿童剃须刀组件不工作?
(Blazor) Why child razor component not working?
我正在尝试将子组件包含到父组件中
但是子组件不工作
下面是代码
==================== 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();
}
我正在尝试将子组件包含到父组件中
但是子组件不工作
下面是代码
==================== 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();
}