Gary H
Gary H

Reputation: 115

Xamarin Forms TapGestureRecognizer not work on UWP

Edited 4/10 - see notes at the end I have a Xamarin Forms multiplatform app using a TapGestureRecognizer to get to a details page. I have it working successfully on Android and iOS however I am now asked to have a UWP version. I have Overview page with different types of forms showing basic information. The problem I'm experiencing is that on a couple of the contentviews (those at the top of the list) I tap and go to the proper details page. But those further down the list, when tapped take me to a random one on the top of the list and never to the proper detail page. I have searched the internet and have found this question asked multiple times but there never seems to be a real answer. So any help will be welcomed. I tried to post the relevant code below, but not knowing where the problem lies, I didn't want to post the whole project either. Edit for clarity The problem is when I run the UWP app on a desktop and am using the mouse pointer and left click to act as the finger tap on a phone's touch screen.

The Overviewpage is a ContentPage with templates in a Flexlayout:

 <ContentPage.Content>
    
    <StackLayout Margin="0,0,0,0">              
            <ScrollView>
                <StackLayout Margin="10,0,10,0">

                    <Label x:Name="FormAHeader" 
                            FontSize="Title"
                            FontFamily="Calibri"
                            TextColor="{StaticResource TracsisGrey}"
                            Text="Form As" />
                    <Label x:Name="lblFormAData" 
                            FontSize="Small"
                            FontFamily="Calibri"
                            TextColor="{StaticResource TracsisGrey}"
                            Text="{Binding BulletinStateText}" BackgroundColor="{Binding BulletinStateColor}" />
                    <FlexLayout Direction="Column"
                            Wrap="NoWrap"
                            AlignItems="Stretch"
                            AlignContent="Center"
                            BindableLayout.ItemsSource="{Binding FormAs}"
                            BindableLayout.ItemTemplate="{StaticResource FormATemplate}" 
                            BindableLayout.EmptyViewTemplate="{StaticResource EmptyFormATemplate}"/>
                    
                    <!--Form Bs-->                      
                    <Label x:Name="FormBHeader" 
                            FontSize="Title"
                            FontFamily="Calibri"
                            TextColor="{StaticResource TracsisGrey}"
                            Text="Form Bs" />
                    <Label x:Name="lblFormBData" 
                            FontSize="Small"
                            FontFamily="Calibri"
                            TextColor="{StaticResource TracsisGrey}"
                            Text="{Binding BulletinStateText}" BackgroundColor="{Binding BulletinStateColor}" />
                    <!--IsVisible="{Binding TWIsVisible}"/>-->
                    <FlexLayout Direction="Column"
                                Wrap="NoWrap"
                                AlignItems="Stretch"
                                AlignContent="Center"
                                BindableLayout.ItemsSource="{Binding FormBs}"
                                BindableLayout.ItemTemplate="{StaticResource FormBTemplate}" 
                                BindableLayout.EmptyViewTemplate="{StaticResource EmptyFormBTemplate}"/>

The contents of the Flexlayout is a ContentView with the TapGestureRecognizer:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:md="clr-namespace:MaterialDesign"             
         xmlns:models="clr-namespace:RailComm.DTW.Mobile.Models"
         x:DataType="models:FormA"
         x:Class="RailComm.DTW.Mobile.Components.FormACard">


<ContentView.Content>
    <Frame>
        <Frame.GestureRecognizers>
        <TapGestureRecognizer CommandParameter="{Binding}" Tapped="FormA_Tapped" />
        </Frame.GestureRecognizers>

        <Grid  >
            <Grid.ColumnDefinitions>

*** Removed lot of the ContentView detail, not sure it is all meaningful

And the Code behind that handles the tapped event:

        private async void FormA_Tapped(object sender, EventArgs e)
    {
        var user = App.LoggedInUser.UserName;

        var ea = e as TappedEventArgs;
        if (ea.Parameter != null)
        {
            var forminfo = JsonConvert.SerializeObject(ea.Parameter);
            string _forminfo = Uri.EscapeDataString(forminfo);
            FormA forma = (FormA)ea.Parameter;
            bool rejectAck = forma.RejectionAcked;
            bool rejected = forma.Rejected;
            string requestor = forma.RequestedBy;
            if (!rejectAck && rejected && requestor == user)
            {
                await Shell.Current.GoToAsync($"{nameof(RejectACK)}?{nameof(RejectACK.Contentx)}={_forminfo}");
            }
            else
            {
                await Shell.Current.GoToAsync($"viewforma?Content={_forminfo}");
            }

        }
    }

4/10 - New information. After playing with this for a while it seems as though the detail page that actually gets selected is not as random as first thought. The form that gets selected is the one that held that position when the screen first displays prior to the user scrolling to other forms. The Overview screen holds 3 summary forms. The user can scroll down for others. After the user scrolls and a different form now sits on the screen where a previous one did and is selected the details of the previous will display. Pic 1 is what displays when the screen first loads with forms 6 , 7 & 5345-0 showing. I've provided a couple screen shots to show this. Pic 2 is after the user has scrolled. Forms 5335-1 sits in the position where form 6 did originally. When I click on it the details of form 6 (Previous pic) will display. Likewise when clicking 5336-1 details for 7 will show and clicking 5337-1 details for 5345-0 will show.

First screen upon loading

Screen after scrolling

Upvotes: 0

Views: 107

Answers (1)

Gary H
Gary H

Reputation: 115

While I don't have a direct answer to the problem, I have uncovered what the cause of the it is, but do not have a resolution. The problem is a RefreshView that is wrapped around the ScrollView. With the RefreshView in place I get the behavior stated above. When I comment it out the tap events work as expected. Since this is a multi-platform project I need the RefreshView for Android & iOS. Furthermore since the problem description is mostly obsolete based on my new findings, I will answer/close this thread and open a new one with more specific information.

Upvotes: 1

Related Questions