2017-01-11 1 views
0

특정 스택 레이아웃의 자식을 반복적으로 프로그램하여 해당 요소의 자식을 가져 오는 것입니다. 반복되는 첫 번째 요소는 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=" &#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> 

그래서 지금과 같은 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에 액세스 할 수있는 방법이 있습니까? 그렇지 않다면, 반복 된 요소의 자식을 어떻게 읽을 수 있는지 알 수 있습니다.

답변

2

당신이 때 내가 할 수있는 답변을 받아 들일 것, 그것은

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

    // now you can use j.Children 
} 
+0

아 네, 그냥이 알아 낸 캐스팅해야합니다. 감사. – jdmdevdotnet

관련 문제