Forum Xamarin.Forms

Disable SwipeView sliding option

Hi,

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 the example I'm using to achieve the sliding and tapping effect:
https://youtube.com/watch?v=1Vs4T6pEi_s

Thanks.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    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.

    If I undstand you correctly , since you want to disable the sliding that open the menu, you can remove the SwipeStarted event and SwipeEnded for the SwipeView.

    Just as follows, you can remove code SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded":

      <SwipeView x:Name="MainSwipeView" BackgroundColor="Transparent"
                       SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded">
                <SwipeView.LeftItems>
                    <SwipeItems>
                        <SwipeItemView>
                            <Grid>
                                <StackLayout Spacing="20" Padding="35" WidthRequest="250" BindableLayout.ItemsSource="{Binding MyMenu}" 
                                             VerticalOptions="CenterAndExpand">
                                    <BindableLayout.ItemTemplate>
                                        <DataTemplate>
                                            <StackLayout Orientation="Horizontal">
                                                <StackLayout.GestureRecognizers>
                                                    <TapGestureRecognizer Tapped="CloseSwipe"/>
                                                </StackLayout.GestureRecognizers>
                                                <pv:PancakeView BackgroundColor="#557ED2" HeightRequest="30" 
                                                                WidthRequest="30" CornerRadius="15" VerticalOptions="Center" 
                                                                HorizontalOptions="Start">
                                                    <Image Source="{Binding Icon}" HeightRequest="15" WidthRequest="15" VerticalOptions="Center" 
                                                           HorizontalOptions="Center"/>
                                                </pv:PancakeView>
                                                <Label Text="{Binding Name}" TextColor="White" FontSize="15" FontAttributes="Bold" 
                                                       HorizontalOptions="Start" VerticalOptions="Center"/>
                                            </StackLayout>
                                        </DataTemplate>
                                    </BindableLayout.ItemTemplate>
                                </StackLayout>
                            </Grid>
                        </SwipeItemView>
                    </SwipeItems>
                </SwipeView.LeftItems>
                <Grid x:Name="swipeContent">
                    <pv:PancakeView x:Name="pancake" BackgroundColor="White">
                           <!--other code-->
                    </pv:PancakeView>
                </Grid>
            </SwipeView>
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • DannyBOAHDannyBOAH Member ✭✭

    Hi, thanks for your reply

    I tried what you suggested and it did not solve my question, after a search I realized that what needs to be done is to disable the possibility of sliding as described in this link:
    https://forums.xamarin.com/discussion/26966/how-to-disable-swipe-gesture-on-pushed-page

    The thing is that they present a solution for the iOS platform and not for Android

  • DannyBOAHDannyBOAH Member ✭✭

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

    // 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();
    }
    
    // Code in xaml
    <SwipeView x:Name="MainSwipeView" BackgroundColor="Transparent"
                       SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded">
    
  • jezhjezh Member, Xamarin Team Xamurai

    Congrats, could you please mark the useful thread as answered so that others who have similar threads will get help from here? Thanks in advance.

Sign In or Register to comment.