Android 上的 SwipeView 轻扫转换模式
此 .NET Multi-platform App UI (.NET MAUI) Android 平台特定功能用于控制打开 SwipeView 时使用的过渡。 其使用方式为,在 XAML 中将 SwipeView.SwipeTransitionMode
可绑定属性设置为 SwipeTransitionMode
枚举的值:
<ContentPage ...
xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls" >
<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 Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
...
SwipeView swipeView = new Microsoft.Maui.Controls.SwipeView();
swipeView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetSwipeTransitionMode(SwipeTransitionMode.Drag);
// ...
SwipeView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>
方法指定这一平台特定功能仅可在 Android 上运行。 Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific
命名空间中的 SwipeView.SetSwipeTransitionMode
方法用于控制打开 SwipeView 时使用的过渡。 SwipeTransitionMode
枚举提供两个可能的值:
Reveal
指示轻扫 SwipeView 内容时将显示轻扫项,它还是SwipeView.SwipeTransitionMode
属性的默认值。Drag
指示轻扫 SwipeView 内容时,轻扫项将被拖动到视图中。
此外,SwipeView.GetSwipeTransitionMode
方法还可用于返回应用于 SwipeView 的 SwipeTransitionMode
。
结果是,指定的 SwipeTransitionMode
值被应用于 SwipeView,该值控制打开 SwipeView 时使用的过渡: