Android 上的 SwipeView 撥動轉換模式

Download Sample 下載範例

此 Android 平臺特定控制開啟 SwipeView時所使用的轉換。 將可繫結屬性設定 SwipeView.SwipeTransitionMode 為 列舉值 SwipeTransitionMode ,以在 XAML 中取用:

<ContentPage ...
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" >
    <StackLayout>
        <SwipeView android:SwipeView.SwipeTransitionMode="Drag">
            <SwipeView.LeftItems>
                <SwipeItems>
                    <SwipeItem Text="Delete"
                               IconImageSource="delete.png"
                               BackgroundColor="LightPink"
                               Invoked="OnDeleteSwipeItemInvoked" />
                </SwipeItems>
            </SwipeView.LeftItems>
            <!-- Content -->
        </SwipeView>
    </StackLayout>
</ContentPage>

或者,您可以使用 Fluent API 從 C# 取用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
...

SwipeView swipeView = new Xamarin.Forms.SwipeView();
swipeView.On<Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag);
// ...

方法 SwipeView.On<Android> 會指定此平台專屬只會在Android上執行。 命名空間 SwipeView.SetSwipeTransitionMode 中的 Xamarin.Forms.PlatformConfiguration.iOSSpecific 方法可用來控制開啟 SwipeView時所使用的轉換。 列舉 SwipeTransitionMode 提供兩個可能的值:

  • Reveal 表示撥動專案會在撥動內容時 SwipeView 顯示,而 是屬性的 SwipeView.SwipeTransitionMode 預設值。
  • Drag 表示撥動專案會在內容撥動時 SwipeView 拖曳到檢視中。

此外, SwipeView.GetSwipeTransitionMode 方法可以用來傳回 SwipeTransitionMode 套用至 的 SwipeView

結果是,指定的 SwipeTransitionMode 值會套用至 SwipeView,這會控制開啟 SwipeView時所使用的轉換:

Screenshot of SwipeView SwipeTransitionModes, on Android