问题描述
我将 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; }
}
解决方法
因为 $ helm dependency list my-chart
并且顺便说一下它是默认值所以你应该省略它,
替换
ItemSpacing="0"
通过
<CollectionView.ItemsLayout>
<LinearItemsLayout ItemSpacing="0" Orientation="Horizontal"/>
</CollectionView.ItemsLayout>