특정 스택 레이아웃의 자식을 반복적으로 프로그램하여 해당 요소의 자식을 가져 오는 것입니다. 반복되는 첫 번째 요소는 Children
개체의 옵션을 제공합니다. 예를 들면 :요소 반복을 통해 반복하는 데 문제가 없습니다.
var TextContainerChildren = TextContainer.Children;
TextContainer 다른 stacklayouts의 무리를 들고 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=" • 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=" • Minor bug fixes." />
<Label x:Name="LabelEmailHelp" Font="15" Text="" />
</StackLayout>
</StackLayout>
그래서 지금과 같은 TextContainer.Children
을 반복하려고 :
foreach(Xamarin.Forms.View el in TextContainerChildren)
{
if(el.GetType() == typeof(Xamarin.Forms.StackLayout))
{
var j = el;
}
}
문제는, el
날 아이들에 액세스 할 수 없습니다. (el.Children
을 시도하면 작동하지 않으며 디버깅 할 때 객체를 보면 Children
이 없습니다.) 그러나 디버깅 할 때 el
은 StackLayout이고 base
은 Children 객체를 볼 수 있습니다.
요소의 base
에 액세스 할 수있는 방법이 있습니까? 그렇지 않다면, 반복 된 요소의 자식을 어떻게 읽을 수 있는지 알 수 있습니다.
아 네, 그냥이 알아 낸 캐스팅해야합니다. 감사. – jdmdevdotnet