如何在另一个之上添加两个StackLayouts?

时间:2017-10-18 09:53:51

标签: xamarin xamarin.forms

我试着这样做:

<ViewCell>
    <StackLayout Padding="0,15,0,0" HeightRequest="300" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical">
        <chart:SfChart x:Name="chart1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        </chart:SfChart>
    </StackLayout>
    <StackLayout Padding="0,15,0,0" HeightRequest="300" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical">
        <chart:SfChart x:Name="chart2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        </chart:SfChart>
    </StackLayout>
</ViewCell>

但只出现第二张图表。

我想要的是看到两个图表,一个在另一个上面。

1 个答案:

答案 0 :(得分:6)

ViewCell只接受一个元素作为子元素。 只需将堆栈包装在另一个StackLayout中:

<ViewCell>
    <StackLayout>
        <StackLayout Padding="0,15,0,0" HeightRequest="300" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical">
            <chart:SfChart x:Name="chart1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            </chart:SfChart>
        </StackLayout>
        <StackLayout Padding="0,15,0,0" HeightRequest="300" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical">
            <chart:SfChart x:Name="chart2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            </chart:SfChart>
        </StackLayout>
    </StackLayout>
</ViewCell>