首页 > 解决方案 > Xamarin.Forms:列表变得比列表视图中的项目长

问题描述

这是我在滚动视图中的网格:

            <ScrollView>
                <Grid>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>


                    <Button  Text="asd1" x:Name="row1" Grid.Row="0"/>

                    <Grid  x:Name="row2" 
                           Grid.Row="1"  
                           IsVisible="false"                           
                           Margin="30,0,0,0" 
                           BackgroundColor="Yellow">


                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <ListView x:Name="list_cat1"
                                  Grid.Row="0">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="auto"/>
                                            </Grid.RowDefinitions>
                                            <Label Text="{Binding subCatName}" >
                                                <Label.GestureRecognizers>
                                                    <TapGestureRecognizer Tapped="GetClick"/>
                                                </Label.GestureRecognizers>
                                            </Label>
                                        </Grid>
                                        
                                    </ViewCell>
                                </DataTemplate>
                                
                            </ListView.ItemTemplate>

                        </ListView>
                    </Grid>

                    <Button Text="asd3"  x:Name="row3"  Grid.Row="2"/>
                </Grid>


            </ScrollView>

但这是我喂它数据_

    private void SetCategories()
    {
        List<CategoryType> allCatsInsideSubs = FilteringSingleton.Instance.GetCategories();

        List<SubCategoryType> sub1 = new List<SubCategoryType>();

        for(int i = 0; i < allCatsInsideSubs.Count; i++)
        {
            if (allCatsInsideSubs[i].categoryOrder == (int)CategoryOdersEnum.Deko)
            {
                SubCategoryType x = new SubCategoryType();
                x.subCatName = allCatsInsideSubs[i].subCategory;
                x.subCatID = allCatsInsideSubs[i].subCategoryOrder;
                sub1.Add(x);
            }

        }

        list_cat1.ItemsSource = sub1;


    }

但结果是这样的:

在此处输入图像描述

如您所见,列表比其中的项目长得多。您实际上可以向下滚动一会儿,直到黄色停止并且下一个按钮变得可见。每一行都设置为自动。这个额外的空间是从哪里来的?

我也注意到,当我将更多数据放入列表视图时,它不再太长

标签: xamarin.forms

解决方案


推荐阅读