如何在 CarouselView 中删除 space(ScrollView 中的 CarouselView)

How to remove space in CarouselView (CarouselView inside ScrollView)

我在 ScrollView 中使用了 CarouselView,因为我只想让 CarouselView 只绑定 Imgae。当我滚动页面时会显示更多信息。我不想在 CarouselView 内部绑定其他信息,因为我只想让其他信息显示在 CarouselView 外部。

<ScrollView VerticalOptions="FillAndExpand" VerticalScrollBarVisibility="Never" HorizontalScrollBarVisibility="Never" HorizontalOptions="FillAndExpand">
<StackLayout Padding="0" Margin="0">
    <StackLayout Padding="0" Margin="0">
        <CarouselView IndicatorView="indicatorView"
                ItemsSource="{Binding ProductInfo.ProductImages}">
            <CarouselView.ItemTemplate>
                <DataTemplate>
                    <StackLayout Padding="0" Margin="0" BackgroundColor="#fff">
                        <Frame HasShadow="False" Padding="0" Margin="15,0" CornerRadius="7" IsClippedToBounds="True">
                            <control:AspectRatioContainer AspectRatio="1">
                                <Image HorizontalOptions="Fill"  Aspect="AspectFill" Source="{Binding Images}"/>
                            </control:AspectRatioContainer>
                        </Frame>
                    </StackLayout>
                </DataTemplate>
            </CarouselView.ItemTemplate>
        </CarouselView>
        <StackLayout Margin="0">
            <IndicatorView x:Name="indicatorView"
                IndicatorColor="#ddd"
                Margin="0,-100,0,0"
                Padding="0"
                BackgroundColor="Transparent"
                SelectedIndicatorColor="#333"
                HorizontalOptions="Center"
                IndicatorSize="5"/>
        </StackLayout>
    </StackLayout>
    <StackLayout Padding="15" Margin="0,0,0,5" BackgroundColor="#fff">
        <Label Text="{Binding ProductInfo.Name}" FontFamily="{StaticResource QuicksandBold}" FontSize="16" HorizontalTextAlignment="Start" TextColor="#333"/>
        <StackLayout>
            <Label TextType="Html" Text="{Binding ProductInfo.ContentsSmall}" HorizontalOptions="Start" HorizontalTextAlignment="Start" FontFamily="{StaticResource QuicksandRegular}" FontSize="13" TextColor="#333"></Label>
        </StackLayout>
    </StackLayout>
</StackLayout>
</ScrollView

但是我想删除下面的空格。

除了设置 CarouselView 的 HeightRequest 之外,请帮我解决任何问题。谢谢!

由于图片是正方形的,我们只需要让CarouselView的高度等于宽度,所以我们可以绑定HeightRequest一个值(屏幕宽度)。

Xaml

 <CarouselView x:Name="cView" IndicatorView="indicatorView" HeightRequest="{Binding ScreenWidth}">

代码隐藏


public double ScreenWidth { get; set; }
public Page1()
{
    InitializeComponent();
    var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
    ScreenWidth = mainDisplayInfo.Width/mainDisplayInfo.Density;
    this.BindingContext = this;
}