דניאל
דניאל

Reputation: 183

Disable SwipeView sliding option

I'm using SwipeView in my project to show and hide the side menu on left of the page. Now I want to to open and hide the menu by tapping on button and not by sliding the page. So far I figure out how to open and hide the menu even by tapping on button but I didn't find solution to how I'm disabling the sliding that open the menu.

Any idea how can I do it in the right way?

Here is my code for achieving the sliding and tapping effect.

This is the Code in 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();
}

This is the Code in xaml

<SwipeView x:Name="MainSwipeView" BackgroundColor="Transparent"
                       SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded">

Thanks.

Upvotes: 1

Views: 1336

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10978

You could set the IsEnabled property to false to disable the swipe.

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>

Before: https://i.sstatic.net/My96f.jpg

After: https://i.sstatic.net/j9jfC.jpg

Upvotes: 1

Related Questions