Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Blazor页面上检索自定义Blazor组件的所有实例_C#_Blazor - Fatal编程技术网

C# 在Blazor页面上检索自定义Blazor组件的所有实例

C# 在Blazor页面上检索自定义Blazor组件的所有实例,c#,blazor,C#,Blazor,我想在Blazor页面上获取Blazor组件的所有实例: 第页: 如何获得三个“搜索过滤器”的列表?我认为Blazor中目前不存在这样的功能。但是,您可以通过向列表对象添加组件引用(@ref directive属性)来创建组件列表,如下所示: 儿童剃须刀 @Title @代码{ [参数] 公共字符串标题{get;set;} } 用法 @if(组件!=null) { @foreach(组件中的var组件) { @组成部分.标题 } } @代码{ ChildComponent ChildCo

我想在Blazor页面上获取Blazor组件的所有实例:

第页:



如何获得三个“搜索过滤器”的列表?

我认为Blazor中目前不存在这样的功能。但是,您可以通过向列表对象添加组件引用(@ref directive属性)来创建组件列表,如下所示:

儿童剃须刀
@Title
@代码{
[参数]
公共字符串标题{get;set;}
}
用法

@if(组件!=null)
{
@foreach(组件中的var组件)
{
@组成部分.标题

} } @代码{ ChildComponent ChildComponent 1; ChildComponent ChildComponent 2; 儿童成分儿童成分3; 列出组件; 受保护的覆盖无效OnAfterRender(布尔firstRender) { if(firstRender) { 组件=新列表(); 组件。添加(子组件1); 组件。添加(子组件2); 组件。添加(子组件3); StateHasChanged(); } } }
请注意,列表仅在呈现页面组件后填充。您以前无法访问组件,因为它们尚未创建

<div class="mb-4 pt-3">
    <SearchFilter Refinement="@refinementAuthor" FilterTitle="Auteur"></SearchFilter>
</div>
<div class="mb-4 pt-3">
    <SearchFilter Refinement="@refinementSubject" FilterTitle="Onderwerp"></SearchFilter>
</div>
<div class="mb-4 pt-3">
    <SearchFilter Refinement="@refinementLanguage" FilterTitle="Taal"></SearchFilter>
</div>
<h3>@Title</h3>

@code {
    [Parameter]
    public string Title { get; set; }

}
<ChildComponent @ref="ChildComponent1" Title="ChildComponent 1"/>
<ChildComponent @ref="ChildComponent2" Title="ChildComponent 2" />
<ChildComponent @ref="ChildComponent3" Title="ChildComponent 3" />

@if (components != null)
{
   @foreach (var component in components)
  {
    <p>@component.Title</p>
  }

}

@code{
  ChildComponent ChildComponent1;
  ChildComponent ChildComponent2;
  ChildComponent ChildComponent3;

  List<ChildComponent> components;

  protected override void OnAfterRender(bool firstRender)
  {
    if (firstRender)
    {
        components = new List<ChildComponent>();
        components.Add(ChildComponent1);
        components.Add(ChildComponent2);
        components.Add(ChildComponent3);

        StateHasChanged();
    }
   }

}