locked
SwipeView Content GestureRecognizers don't work RRS feed

  • Question

  • User390943 posted

    Hi ho,

    I have a ListView, where each element is a SwipeView. The SwipeView inherits a Label with a TabGestureRecognizer. ```xaml

                                </Label>
                        </SwipeView>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    

    ```

    CodeBehind ``` using System; using Xamarin.Forms; using Xamarin.Forms.Xaml;

    namespace App2 { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class Page2 : ContentPage { public Page2() { InitializeComponent();

        }
    
        void TapGestureRecognizer_Tapped(Object sender, EventArgs e)
        {
            Console.WriteLine("HEY");
        }
    }
    

    } ```

    My question: How can I reach the TabGestureRecognizer? At the moment the event isn't triggered while tabbing on the label.

    Thursday, March 12, 2020 1:26 PM

Answers

  • User369979 posted

    Here is my effect on Android:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 13, 2020 8:21 AM

All replies

  • User369979 posted

    I tested your code on Android it worked properly. But for iOS, we need to use a layout to wrap the content like:

    <ViewCell>
        <SwipeView>
            <SwipeView.RightItems>
                <SwipeItems>
                    <SwipeItem Text="Favorite"
                                    BackgroundColor="LightGreen"/>
                    <SwipeItem Text="Delete"
                                    BackgroundColor="LightPink"/>
                </SwipeItems>
            </SwipeView.RightItems>
            <Grid>
                <Label Text="Swipe left"
                            HorizontalOptions="Center"
                            VerticalOptions="Center" >
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
                    </Label.GestureRecognizers>
                </Label>
            </Grid>
        </SwipeView>
    </ViewCell>
    

    Add a test alert in the tapped event:

    private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
        DisplayAlert("", "Tapped", "OK");
    }
    

    Here is the effect:

    Friday, March 13, 2020 3:05 AM
  • User390943 posted

    Sorry.... I have the feeling that I am missing something stupid here. I have exactly the same code and try to build it on my android device, but Labels, Buttons, etc. don't fire events inside the SwipeView. Also added The Flag in MainActivity. global::Xamarin.Forms.Forms.SetFlags("SwipeView_Experimental");

    (Would love to send a sample here, but file-size is to big)

    Friday, March 13, 2020 8:07 AM
  • User369979 posted

    Here is my effect on Android:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, March 13, 2020 8:21 AM