.NET MAUI 垂直SwipeView(抖音幻灯片等)

问题描述 投票:0回答:1

我需要通过在 .NET MAUI 中向上或向下滚动来查看列表中的项目。我的列表中有一些使用 YoutubeApi 和 MediaElement 展示的视频。 (Tiktok、Instagram Reels 等)我想在这里做什么;

无论哪个项目当前可见,该项目的

MediaElement.Play()
都应该起作用。无论如何我找不到合适的滚动事件。有人对此有什么想法吗?

感谢您的帮助。 enter image description here

我已经尝试了所有附加的方法来做到这一点,但没有成功。+

https://help.syncfusion.com/maui/cards/getting-started https://www.syncfusion.com/maui-controls/maui-rotator https://github.com/AndreiMisiukevich/CardView.MAUI

.net xamarin maui cardview swipeview
1个回答
0
投票

这可以使用具有线性布局捕捉点CollectionView轻松实现:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
  x:Class="FullPageSnapCollection.MainPage"
  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:fullPageSnapCollection="clr-namespace:FullPageSnapCollection"
  x:DataType="fullPageSnapCollection:MainViewModel">

  <Grid>

    <CollectionView
      HeightRequest="500"
      HorizontalOptions="Fill"
      VerticalOptions="Center"
      ItemsSource="{Binding Items}">

      <CollectionView.ItemsLayout>
        <LinearItemsLayout
          Orientation="Vertical"
          SnapPointsType="MandatorySingle"
          SnapPointsAlignment="Start" />
      </CollectionView.ItemsLayout>

      <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="fullPageSnapCollection:MyModel">
          <Grid
            HeightRequest="500"
            BackgroundColor="{Binding BackgroundColor}"
            HorizontalOptions="Fill">
            <Label
              Text="{Binding Name}"
              VerticalOptions="Center"
              HorizontalOptions="Center"
              FontSize="Title" />
          </Grid>
        </DataTemplate>
      </CollectionView.ItemTemplate>

    </CollectionView>

  </Grid>

</ContentPage>

您需要为

CollectionView
提供 HeightRequest 以及 DataTemplate 中的布局,以便项目与 CollectionView 具有相同的高度。与捕捉点一起,这应该会产生您正在寻找的内容。

我为此创建了一个小示例存储库:https://github.com/ewerspej/FullPageSnapCollection

© www.soinside.com 2019 - 2024. All rights reserved.