首页 > 解决方案 > 如何在 ListView XAML 中添加多个 Frame

问题描述

我想添加几个帧,如下图所示:

框架

问题是这些在 a 内<ListView>,它不允许我在<View>标签内添加多个

当我添加第二个时,我收到以下错误:

多次设置“视图”属性。

我附上了我的 LIstView 结构的屏幕截图,以获得更详细的信息及其各自的代码。

  <ListView 
                ItemsSource="{Binding Reportes}"
                SelectionMode="None"
                Margin="0,0,10,0"
                HasUnevenRows="true">
                <ListView.ItemTemplate>
                    <DataTemplate>
                    <ViewCell>  
                        <Frame
                            CornerRadius="15"
                            HasShadow="True"
                            Padding="5"
                            BackgroundColor="{StaticResource das.color.estado_primary}">                     
                            <StackLayout 
                                    Orientation="Horizontal"
                                    BackgroundColor="{StaticResource das.color.estado_primary}">
                                <Image
                                    Source="barrascf"
                                    HeightRequest="80"
                                    WidthRequest="80"
                                    Opacity="1">
                                </Image>
                                <StackLayout
                                    Orientation="Vertical"
                                    HorizontalOptions="EndAndExpand"
                                    BackgroundColor="{StaticResource das.color.estado_primary}">
                                    <Label
                                            Text="{Binding ArticulosTotales}"
                                            TextColor="White">
                                    </Label>
                                    <Label
                                            Text="ARTICULOS TOTALES"
                                            TextColor="White">
                                    </Label>
                                </StackLayout>
                            </StackLayout>                       
                    </Frame>

                            <Frame
                            CornerRadius="15"
                            HasShadow="True"
                            Padding="5"
                            BackgroundColor="{StaticResource das.color.estado_primary}">
                                <StackLayout 
                                    Orientation="Horizontal"
                                    BackgroundColor="{StaticResource das.color.estado_primary}">
                                    <Image
                                    Source="barrascf"
                                    HeightRequest="80"
                                    WidthRequest="80"
                                    Opacity="1">
                                    </Image>
                                    <StackLayout
                                    Orientation="Vertical"
                                    HorizontalOptions="EndAndExpand"
                                    BackgroundColor="{StaticResource das.color.estado_primary}">
                                        <Label
                                            Text="{Binding ArticulosTotales}"
                                            TextColor="White">
                                        </Label>
                                        <Label
                                            Text="ARTICULOS TOTALES"
                                            TextColor="White">
                                        </Label>
                                    </StackLayout>
                                </StackLayout>
                            </Frame>
                        </ViewCell>

                </DataTemplate>
                </ListView.ItemTemplate>                
            </ListView>      

截图

我究竟做错了什么?我应该如何构建我的 XAML 代码?对我有什么帮助吗?

标签: xamllistviewxamarinxamarin.formsframe

解决方案


任何时候您需要将多个视图添加到只接受单个子控件的控件中,您可以通过将它们包装在布局容器(堆栈、网格等)中来实现

<ViewCell>
  <StackLayout>
    <Frame/>
    <Frame/>
    <Frame/>
  </StackLayout>
</ViewCell>

推荐阅读