禁用滑动滑动选项



我在我的项目中使用SwipeView来显示和隐藏页面左侧的侧菜单。现在我想通过点击按钮来打开和隐藏菜单,而不是滑动页面。到目前为止,我知道如何打开和隐藏菜单,甚至通过点击按钮,但我没有找到解决方案,我如何禁用滑动打开菜单。

你知道我该怎么做吗?

这是我实现滑动和敲击效果的代码。

这是xaml.cs中的代码:

private async void OpenAnimation()
{
await swipeContent.ScaleYTo(0.9, 300, Easing.SinOut);
}
private async void CloseAnimation()
{
await swipeContent.RotateTo(0, 300, Easing.SinOut);
}
private void OpenSwipe(object sender, EventArgs e)
{
MainSwipeView.Open(OpenSwipeItem.LeftItems);
OpenAnimation();
}
private void CloseSwipe(object sender, EventArgs e)
{
MainSwipeView.Close();
CloseAnimation();
}
private void SwipeStarted(object sender, SwipeStartedEventArgs e)
{
OpenAnimation();
}
private void SwipeEnded(object sender, SwipeEndedEventArgs e)
{
if (!e.IsOpen)
CloseAnimation();
}

这是xaml

中的代码
<SwipeView x:Name="MainSwipeView" BackgroundColor="Transparent"
SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded">

谢谢。

您可以将IsEnabled属性设置为false以禁用滑动。

xaml:

<StackLayout HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<SwipeView IsEnabled="False">
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem
BackgroundColor="LightGreen"
IconImageSource="grapes_24.png"
Invoked="Favorite_Invoked"
Text="Favorite" />
<SwipeItem
BackgroundColor="LightPink"
IconImageSource="star_small.png"
Invoked="Delete_Invoked"
Text="Delete" />
</SwipeItems>
</SwipeView.LeftItems>
<Grid
BackgroundColor="LightGray"
HeightRequest="60"
WidthRequest="300">
<Label
HorizontalOptions="Center"
Text="Swipe right"
VerticalOptions="Center" />
</Grid>
</SwipeView>
</StackLayout>

:https://i.stack.imgur.com/My96f.jpg

后:https://i.stack.imgur.com/j9jfC.jpg

最新更新