我有这段代码:
<local:CustomTextCell x:Name="cfs0" />
<local:CustomTextCell x:Name="cfs1" />
<local:CustomTextCell x:Name="cfs2" />
有没有办法可以使用数组而不是使用这三个名字?
原因是我想使用for循环来改变单元格属性。
答案 0 :(得分:3)
您可以为父class InContainer
{
public InContainer(NotInContainer dependency) { ... }
}
class Consumer
{
public Consumer(IServiceProvider serviceProvider)
{
NotInContainer currentDependency = ... // from some other source
// passing the anonymous object here is not supported,
// but I would like to
InContainer = serviceProvider.GetService<InContainer>(
new { dependency = currentDependency }
);
}
}
添加名称,并使用它循环遍历所有单元格。
TableSection
添加循环逻辑如下:
<TableSection Title="Parent" x:Name="parentSection">
<local:CustomTextCell x:Name="cfs0" />
<local:CustomTextCell x:Name="cfs1" />
<local:CustomTextCell x:Name="cfs2" />
</TableSection>