Langauge tranlation is not working when adding GestureRecognizers in contentview

Ashwini Shetty 1 Reputation point
2021-06-03T08:45:35.883+00:00

Hi ,
I am working on Xamarin forms application. I have some issue in langauge selection in iPhone.
If i remove GestureRecognizerse from contentview then everything works fine.

         <ContentView.GestureRecognizers>
                 <TapGestureRecognizer Tapped="closePopup"/>
        </ContentView.GestureRecognizers>

this is my code . SelectedItem in collection view is not triggering when I add GestureRecognizers in COntentview.

  <ContentView x:Name="languagePopup" BackgroundColor="#C0808080" IsVisible="{Binding LanguagePopup}" AbsoluteLayout.LayoutBounds="0,1,1,0.87" AbsoluteLayout.LayoutFlags="All">
     <ContentView.GestureRecognizers>
                    <TapGestureRecognizer Tapped="closePopup"/>
                 </ContentView.GestureRecognizers>
                 <Frame CornerRadius="2" WidthRequest="120" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand" BackgroundColor="White" HeightRequest="120" Margin="0,0,15,0" Padding="5">
                <StackLayout VerticalOptions="Center" HorizontalOptions="Center">

                       <CollectionView x:Name="collectionView" ItemsSource="{Binding language}" SelectionMode="Single" SelectedItem="{Binding SelectLangauge, Mode=TwoWay}" >

                           <CollectionView.ItemTemplate>
                               <DataTemplate>

                              <StackLayout Orientation="Horizontal" Margin="10,5,10,5" >

                                  <Image  Source="{Binding Image}" HeightRequest="20" WidthRequest="20" VerticalOptions="Center"/>
                                  <Label  Text="{Binding Value}" Margin="0,2,0,5" TextColor="#333333"  VerticalOptions="Center" AutomationId="Language0"/>

                                </StackLayout>
                               </DataTemplate>
                           </CollectionView.ItemTemplate>
                       </CollectionView>

                </StackLayout>


                </Frame>

               </ContentView>        

Please help me with this

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,335 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-06-04T07:13:29.633+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    SelectedItem in collection view is not triggering when I add GestureRecognizers in COntentview.

    Yes, it is just the case as you said.

    There is a tap recognizer conflict between the TapGestureRecognizer of the outer ContentView and the inner CollectionView .

    Android has the same problem, but in a different way.

    If we add function closePopup for the Tapped event of the TapGestureRecognizer as follows:

        <ContentView x:Name="languagePopup" BackgroundColor="Yellow"  >  
            <ContentView.GestureRecognizers>  
                <TapGestureRecognizer  Tapped="closePopup"></TapGestureRecognizer>  
            </ContentView.GestureRecognizers>  
    
           <!--other code-->  
    
       </ContentView >  
    

    function closePopup in xaml.cs:

        private void closePopup(object sender, System.EventArgs e)  
        {  
            DisplayAlert("Alert", "You have been alerted", "OK");  
        }  
    

    In android, we couldn't pop up the DisplayAlert in function closePopup, but SelectedItem in collection view is triggering normally.
    In Ios, we could pop up the DisplayAlert in function closePopup,but SelectedItem in collection view isn't triggering normally.

    That's based on the difference of different platform(android,ios ).

    As a summary, when two controls are nested, we should never use the tap recognition of two controls together.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.