我想在我的應用程式上使用全域加載指示器。我已經有一個組件,LoadingIndicator.razor:
<CascadingValue Value="this">
<TelerikLoaderContainer Visible="@( IsVisible )" Text="@Text" />
@ChildContent
</CascadingValue>
@code {
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter]
public bool IsVisible { get; set; }
[Parameter]
public string Text { get; set; } }
在我的組件樹中的某處,我嘗試了以下操作,childComponent.razor
[CascadingParameter]
protected LoadingContainer LoadingContainer { get; set; }
protected override async Task OnInitializedAsync()
{
LoadingContainer.Text = "test";
LoadingContainer.IsVisible = true;
}
根據 warning BL0005thats not allowed due to inconsistent Ui (possibly). 但是我怎樣才能在我的子組件上顯示加載指示器呢?我不想使用繼承,因為我想靈活地選擇是否使用它以及在何處使用它。CascadingValue 在MainLayout級別上應用,因此所有組件都可用。
uj5u.com熱心網友回復:
您想要在父級中觸發更新。
<CascadingValue Value="this">
<TelerikLoaderContainer Visible="@( IsVisible )" Text="@Text" />
@ChildContent
</CascadingValue>
@code {
[Parameter]
public RenderFragment? ChildContent { get; set; }
//[Parameter] -- you can make these private fields now
public bool IsVisible { get; set; }
//[Parameter] -- same
public string Text { get; set; }
public void ShowLoader(string text)
{
Text = text;
IsVisible = true;
StateHasChanged();
}
}
并像這樣使用它
protected override async Task OnInitializedAsync()
{
//LoadingContainer.Text = "test";
//LoadingContainer.IsVisible = true;
LoadingContainer.ShowLoader("test");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/535903.html
標籤:。网开拓者泰勒里克blazor-webassembly
