首页 > 解决方案 > 禁用 SwipeView 滑动选项

问题描述

我在我的项目中使用 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">

谢谢。

标签: c#xamarinxamarin.formsswipeview

解决方案


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

xml:

  <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 ://imgur.com/vKDpplO

之后: https ://imgur.com/0jPDRB3


推荐阅读