C# 在元素的迭代中进行迭代时出现问题

C# 在元素的迭代中进行迭代时出现问题,c#,xamarin.forms,C#,Xamarin.forms,因此,只需通过编程迭代特定stacklayout的子元素,并获取这些元素的子元素。我遍历的第一个元素为我提供了子对象的选项。因此: <StackLayout x:Name="TextContainer" Padding="10,10,10,0"> <Label Text="What's New" FontSize="20" /> <!--<StackLayout Orientation="Vertical

因此,只需通过编程迭代特定stacklayout的子元素,并获取这些元素的子元素。我遍历的第一个元素为我提供了
子对象的选项。因此:

<StackLayout x:Name="TextContainer" Padding="10,10,10,0">
              <Label Text="What's New" FontSize="20" />
              <!--<StackLayout Orientation="Vertical" Padding="0,10,0,10">
                <Label Font="15" Text="Version 2.3.1 - January 9, 2017" TextColor="Blue" />
                <Label Font="15" Text=" &#8226; Breaking News Push Notifications. Users can now subscribe to breaking news push notifications that display an alert on your phone when a breaking news story is published." />
                <Label x:Name="LabelEmailHelp" Font="15" Text="" />
              </StackLayout>-->

              <StackLayout Orientation="Vertical" Padding="0,10,0,10">
                <Label Font="15" Text="Version 2.3.1 - January 12, 2017" TextColor="Blue" />
                <Label Font="15" Text=" &#8226; Minor bug fixes." />
                <Label x:Name="LabelEmailHelp" Font="15" Text="" />
              </StackLayout>
</StackLayout>
var TextContainerChildren=TextContainer.Children

TextContainer是一个StackLayout,包含一组其他StackLayout。因此:

<StackLayout x:Name="TextContainer" Padding="10,10,10,0">
              <Label Text="What's New" FontSize="20" />
              <!--<StackLayout Orientation="Vertical" Padding="0,10,0,10">
                <Label Font="15" Text="Version 2.3.1 - January 9, 2017" TextColor="Blue" />
                <Label Font="15" Text=" &#8226; Breaking News Push Notifications. Users can now subscribe to breaking news push notifications that display an alert on your phone when a breaking news story is published." />
                <Label x:Name="LabelEmailHelp" Font="15" Text="" />
              </StackLayout>-->

              <StackLayout Orientation="Vertical" Padding="0,10,0,10">
                <Label Font="15" Text="Version 2.3.1 - January 12, 2017" TextColor="Blue" />
                <Label Font="15" Text=" &#8226; Minor bug fixes." />
                <Label x:Name="LabelEmailHelp" Font="15" Text="" />
              </StackLayout>
</StackLayout>
问题是,
el
不允许我访问孩子们。(尝试执行
el.Children
不起作用,我的意思是,当我在调试中查看对象时,没有
子对象
)。但是,在调试时,我可以看到
el
是一个StackLayout,在
base
中我可以看到子对象

是否有任何方法可以访问元素的
base
?如果没有,有人知道我如何读取迭代元素的子元素吗

你需要投下它

if(el.GetType() == typeof(Xamarin.Forms.StackLayout))
{
    StackLayout j = (StackLayout)el;

    // now you can use j.Children
}

啊,是的,刚刚弄明白了,我会在可能的时候接受你的回答。谢谢