Xamarin Carousel View:达到峰值时对齐当前项目中心?
Xamarin Carousel View: Align current item center when peaking?
我有一个 Xamarin Carousel 视图,其中 PeakAreaInsets 设置得非常高,这样我可以一次看到列表中的多个项目。但是我注意到当前项目设置为对齐时,当我希望它对齐到页面中心时,它会更多地与页面顶部对齐。我怎样才能做到这一点?
这里是有问题的代码片段:
<ContentPage.Content>
<CarouselView ItemsSource="{Binding Days}"
CurrentItem="{Binding SelectedDay}"
VerticalOptions="Center"
HorizontalOptions="Center"
PeekAreaInsets="300"
x:Name="DayCarousel">
<CarouselView.ItemsLayout>
<LinearItemsLayout SnapPointsAlignment="Center"
SnapPointsType="Mandatory"
Orientation="Vertical"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout Spacing="0"
Orientation="Vertical"
HorizontalOptions="Center"
VerticalOptions="Center"
Margin="30,10">
<Label Text="{Binding FormattedDate}"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{StaticResource LabelStyle}"/>
<Label Text="{Binding TitleText}"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{StaticResource LabelHeader1Style}"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding BindingContext.SelectDay, Source={x:Reference this}}"
CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage.Content>
这是它现在的样子(只是一个模型):
我希望它看起来像这样:
我最后试了一下。我不确定它在其他 phone 格式和尺寸上的效果如何,因为我还没有测试过。但最终我在调整 PeakAreaInsets
和调整 SnapPointsAlignment
后找到了一个快乐的媒介。目前我将其设置为 PeakAreaInsets = 350
和 SnapPointsAlignment="Start"
我有一个 Xamarin Carousel 视图,其中 PeakAreaInsets 设置得非常高,这样我可以一次看到列表中的多个项目。但是我注意到当前项目设置为对齐时,当我希望它对齐到页面中心时,它会更多地与页面顶部对齐。我怎样才能做到这一点?
这里是有问题的代码片段:
<ContentPage.Content>
<CarouselView ItemsSource="{Binding Days}"
CurrentItem="{Binding SelectedDay}"
VerticalOptions="Center"
HorizontalOptions="Center"
PeekAreaInsets="300"
x:Name="DayCarousel">
<CarouselView.ItemsLayout>
<LinearItemsLayout SnapPointsAlignment="Center"
SnapPointsType="Mandatory"
Orientation="Vertical"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout Spacing="0"
Orientation="Vertical"
HorizontalOptions="Center"
VerticalOptions="Center"
Margin="30,10">
<Label Text="{Binding FormattedDate}"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{StaticResource LabelStyle}"/>
<Label Text="{Binding TitleText}"
HorizontalOptions="Center"
VerticalOptions="Center"
Style="{StaticResource LabelHeader1Style}"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding BindingContext.SelectDay, Source={x:Reference this}}"
CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage.Content>
这是它现在的样子(只是一个模型):
我希望它看起来像这样:
我最后试了一下。我不确定它在其他 phone 格式和尺寸上的效果如何,因为我还没有测试过。但最终我在调整 PeakAreaInsets
和调整 SnapPointsAlignment
后找到了一个快乐的媒介。目前我将其设置为 PeakAreaInsets = 350
和 SnapPointsAlignment="Start"