所以我在这里做的是,我的子组件(RMSBaseComponent.razor)中有一个进度条,该进度条被条件变量“ IsLoading”包围
<div style="padding:20px">
@* Page Title *@
<h3>@PageTitle</h3>
<MatDivider></MatDivider>
@* Loader *@
@if (IsLoading)
{
<MatProgressBar Indeterminate="true"></MatProgressBar>
}
</div>
我将这个孩子放在Parent(AddNewCity.razor)中,为
<RMSBaseComponent PageTitle="Add New City" @ref="BaseComponent">
</RMSBaseComponent>
在这里,我在“ BaseComponent”变量中获取子代的引用,但是当我从父组件类(AddNewCity.cs)更改“ IsLoading”的值时,它不会更新UI且未显示“ MatProgressBar” UI。我正在如下更改值
public partial class AddNewCity
{
private RMSBaseComponent BaseComponent { get; set; }
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
Thread.Sleep(3000);
BaseComponent.IsLoading = true;
}
}
将提供任何帮助。
谢谢
答案 0 :(得分:1)
您应在StateHasChanged()
之后致电Thread.Sleep()
public partial class AddNewCity
{
private RMSBaseComponent BaseComponent { get; set; }
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
Thread.Sleep(3000);
BaseComponent.IsLoading = true;
StateHasChanged();
}
}