Forum Xamarin.Forms

TapGestureRecognizers stopped working.

bkaankosebkaankose USMember ✭✭
edited June 2015 in Xamarin.Forms

I've been working on Xamarin Forms project for iOS (iPad) and Windows Store.I have 3 images with tap gestures , and they were working.Somehow , they stopped working and I don't know why ... Here's my XAML code . :

<Grid Grid.ColumnSpan="2" IsVisible="{Binding ErrorVisibility}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Column="0" BackgroundColor="Black" Opacity="0.7">
  <Grid WidthRequest="500" HeightRequest="300" BackgroundColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
    <Grid.RowDefinitions>
      <RowDefinition Height="50"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
      <RowDefinition Height="100"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" BackgroundColor="Red">
      <Label VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Text="{Binding Source='',Converter={StaticResource LocalizationConverter},ConverterParameter='ERROR_REPORT'}" FontSize="22" TextColor="White"></Label>
    </Grid>
    <ContentView Grid.Row="1" Padding="10,10,10,10">
      <Label Text="{Binding ErrorMessage}" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" TextColor="Black" FontSize="23"></Label>
    </ContentView>
    <ContentView HorizontalOptions="End" Grid.Row="2" Padding="5,5,5,5">
      <StackLayout Orientation="Horizontal">
        <Image x:Name="tickImage" IsVisible="{Binding TickVisibility}" Source="{Binding Tick_Icon,Source={StaticResource ResourceService}}"></Image>
        <Image x:Name="crossImage" IsVisible="{Binding CrossVisibility}" Source="{Binding Cross_Icon,Source={StaticResource ResourceService}}" />
        <Image x:Name="webImage" IsVisible="{Binding NavigateImageVisibility}" Source="{Binding Web_Icon,Source={StaticResource ResourceService}}" />
      </StackLayout>
    </ContentView>
  </Grid>
 </Grid>

I'm adding TapGestureRecognizer for each Image and binding them to Command in ViewModel.

private void InitializeComponentExtra()
        {
            var tapRecognizer = new TapGestureRecognizer();
            var tickRecognizer = new TapGestureRecognizer();
            var crossRecognizer = new TapGestureRecognizer();

            tapRecognizer.Tapped += (c, r) => { _LoginPageVM.LoginCommand.Execute(null); };
            tickRecognizer.Tapped += (c, r) => { _LoginPageVM.TickCommand.Execute(_LoginPageVM.CrashReport); };
            crossRecognizer.Tapped += (c, r) => 
            {
                _LoginPageVM.CrossCommand.Execute(null);
            };

            tickImage.GestureRecognizers.Add(tickRecognizer);
            crossImage.GestureRecognizers.Add(crossRecognizer);
            btnLogin.GestureRecognizers.Add(tapRecognizer);
        }

I see days that theese codes were working , but somehow they're not now.Events are never triggered.I didn't update my Xamarin.Forms version and didn't change anything in XAML & code side.

What you guys do think that is the problem ?

Thanks in advance.

Best Answer

  • bkaankosebkaankose US ✭✭
    Accepted Answer

    I can read the changelog and don't want to break my working version.Anyways , thanks for your suggestions.I've moved webImage to another position and problem solved.Obviously , unvisible images with TapGestures breaking somethings in the behind.

Answers

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    if you put a breakpoint on this line

    _LoginPageVM.CrossCommand.Execute(null);

    does it break on it

  • bkaankosebkaankose USMember ✭✭

    No , it doesn't.EventHandlers never triggering.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    you are throwing in so many variables
    you mention iOS and Windows Store. XF Windows Store support is in beta.
    its not working for neither iOS and WinStore?
    also you don't show where you this Grid. is it right in a Page?

  • bkaankosebkaankose USMember ✭✭

    It's not working on both platforms and was working on both platforms as well.

    The Grid itself is in the center of the screen but it's in another Grid with Stretched (FillAndExpanded) Grid , I didn't post it because it seemed redundant to me.Here it is :

    <Grid Grid.ColumnSpan="2" IsVisible="{Binding ErrorVisibility}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Column="0" BackgroundColor="Black" Opacity="0.7">
    
    </Grid>
    
  • AndrewMobileAndrewMobile USMember ✭✭✭✭
    edited June 2015

    and the Xamarin and XF version?
    do you have latest stable?

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    can you make ErrorVisibility and CrossVisibility true right from the start?
    maybe it's an issue with making it visible

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    also if you put a breakpoint somewhere after InitializeComponentExtra is run for example, does crossImage have Tapped not null for example?

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    usually the source of these issue is completely different :)

  • bkaankosebkaankose USMember ✭✭

    Nothing is null , my Xamarin Version is 3.11.586 (1 older from latest stable) , I don't have problems with Visibilities since I can hide / show anytime I want.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    why dont you use Xamarin latest stable versions ?

  • bkaankosebkaankose USMember ✭✭

    It has nothing to do with my current problem :)

    • When I remove the latest Image (webImage) , it works.
    • If I set webImage's Visibility to True , it works.
    • If I set webImage's Visibility to False , it does not work.

    Simply , if webImage is not null and Visible , it does not work.If it's Visible , all tappings work.Weird interaction.Might be a bug with TapGestureRecognizers in general.If I find some other details about this problem I'll post it to bugzilla.

    Thanks in advance.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    How do you know it has nothing to do with it?
    Why would you post a bug for a previous stable version?

  • bkaankosebkaankose USMember ✭✭
    Accepted Answer

    I can read the changelog and don't want to break my working version.Anyways , thanks for your suggestions.I've moved webImage to another position and problem solved.Obviously , unvisible images with TapGestures breaking somethings in the behind.

Sign In or Register to comment.