扩展器在展开时切断了 CollectionView 的一部分

问题描述

我将 Xamarin.Forms 5 与 Community Toolkit 1.02 一起使用。 Expander 似乎对正文中的静态内容工作正常,但是当我添加 CollectionView 时,内容底部被切断了。

如果我滚动到最初可见的区域之外,项目就会显示出来。下面是我用于短动画的简化 XAML 和模型。我做错了什么?

XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="SandBox.Views.ExpanderPage">
    <ContentPage.Content>
        <xct:Expander>
            <xct:Expander.Header>
                <Label Text="Header" Padding="20" BackgroundColor="LightCyan"/>
            </xct:Expander.Header>
            <StackLayout HeightRequest="160" BackgroundColor="Aquamarine">
                <CollectionView
                            ItemsSource="{Binding Items}"
                            VerticalOptions="End" 
                            SelectionMode="Single">
                    <CollectionView.ItemsLayout>
                        <LinearItemsLayout ItemSpacing="0" Orientation="Horizontal" />
                    </CollectionView.ItemsLayout>
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout 
                                WidthRequest="160"
                                HeightRequest="160"
                                BackgroundColor="Orange"
                                Spacing="0">
                                <Label Text="{Binding Text}" BackgroundColor="LightSkyBlue"/>
                                <Label Text="{Binding Text}" BackgroundColor="LightSkyBlue"/>
                                <Label Text="{Binding Text}" BackgroundColor="LightSkyBlue"/>
                                <Label Text="{Binding Text}" BackgroundColor="LightSkyBlue"/>
                            </StackLayout>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
            </StackLayout>
        </xct:Expander>
    </ContentPage.Content>
</ContentPage>

模型:

public class Expanderviewmodel : Baseviewmodel
{
    public ObservableCollection<ExpanderItem> Items { get; }
    public Expanderviewmodel()
    {
        Items = new ObservableCollection<ExpanderItem>() { 
            new ExpanderItem(){Text = "Item 1" },new ExpanderItem(){Text = "Item 2" },new ExpanderItem(){Text = "Item 3" },new ExpanderItem(){Text = "Item 4" },};
    }
}

public class ExpanderItem
{
    public string Text { get; set; }
}

enter image description here

解决方法

因为 $ helm dependency list my-chart 并且顺便说一下它是默认值所以你应该省略它,

替换

ItemSpacing="0"

通过

<CollectionView.ItemsLayout>
     <LinearItemsLayout ItemSpacing="0" Orientation="Horizontal"/>
</CollectionView.ItemsLayout>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...