Gesture Recognizers in XAML?

binkman71binkman71 USMember ✭✭

In my Xaml I put the following:

    <Image x:Name="imgSettings"... >
      <Image.GestureRecognizers>
        <TapGestureRecognizer TappedCallback="Settings_Clicked"/>
      </Image.GestureRecognizers>
    </Image>

It compiles without complaint, but the callback is never called...

Did I leave something out? Is this possible in Xaml, or do I need to add the gestures in C#?

Posts

  • PippoCanePippoCane USMember ✭✭

    Anything here? I've got the same problem. Btw, works ok when wiring the event in the constructor.

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    @binkman71‌ this:

    <TapGestureRecognizer TappedCallback="Settings_Clicked"/>
    

    is event wiring syntax. TappedCallback is an Action, not an event.

    You could make that works by Binding to the TappedCallback.

    Anyway, I'm filing this for investigation, and make it more xaml friendly, either by exposing a Command, or an event.

  • NayZaKNayZaK USMember ✭✭

    Anyway, I'm filing this for investigation, and make it more xaml friendly, either by exposing a Command, or an event.

    And how it looks in xaml?

  • AndrewBilykAndrewBilyk USMember

    @StephaneDelcroix‌ Trying to set TapGestureRecognizer's Tapped event from Xaml -- as shown directly above -- doesn't work. Testing on both Android and WinPhone, I get an Unhandled Exception.

    Note that setting the Command from Xaml (as shown) and setting the Tapped event from the codebehind both work.

    Please advise, or add this to the todo list? Thanks!

  • CraigDunnCraigDunn USXamarin Team Xamurai

    Yep @AndrewBilyk‌, we did notice that setting the Tapped property in Xaml still wasn't working right... it should be fixed in the next release :)

  • CorradoCavalliCorradoCavalli ITInsider, University ✭✭

    What is actual status? Running v 1.2.2 and Tapped event in XAML works on Windows Phone but not on Android (haven't tried on iOS)

  • CraigDunnCraigDunn USXamarin Team Xamurai

    What's the exact XAML you're using?

  • DrewHarrisDrewHarris USMember

    I'm having a seemingly related issue, using Xamarin Forms version 1.3.1 prerelease.

    I've used the examples in the Gestures documentation, and I keep getting 'Object does not match target type.'

    XAML:
    <TableView> <TableView.Root> <TableSection Title="Test"> <ViewCell> <View.GestureRecognizers> <TapGestureRecognizer Tapped="TestTapped"/> </View.GestureRecognizers> <StackLayout Orientation="Horizontal"> <Label Text="Label"/> </StackLayout> </ViewCell> </TableSection> </TableView.Root> </TableView>

    Codebehind:
    public void TestTapped(object sender, EventArgs e) { Navigation.PushAsync(new ContentPage {Content = new Label {Text = "Working"}}); }

    Any help would be appreciated.

  • LuckyDayLuckyDay USMember ✭✭✭

    ViewCell isn't a View. Put GestureRecognizers on the StackLayout, not the ViewCell.

  • DrewHarrisDrewHarris USMember

    Thanks, that did it.

  • priyakarthicpriyakarthic INMember

    Hi
    Why TapGestureRecognizer is not working in IOS? in xamarin forms pcl


    <Image.GestureRecognizers>

    </Image.GestureRecognizers>

  • I am having the same problem,
    <Image.GestureRecognizers>

    </Image.GestureRecognizers>

    It's not working on ios, it works fine on android. Can anyone help?

  • Also I noticed that for some reason it looks like that none of the binding with code behind is working. I commented out the codes for binding from xaml and it run but as soon I put the binding it threw an error saying that cannot find the method, so it seems that my xaml is not connecting with .cs (code behind)?

  • Vasia_LuVasia_Lu UAMember
    edited February 2017

    I am having the same problem
    <Label x:Name="AcceptLabel" Text="Accept" VerticalTextAlignment="Center" Grid.Column="3" TextColor="#4598d5"> <Label.GestureRecognizers> <TapGestureRecognizer Tapped="OnAcceptTapped" NumberOfTapsRequired="1" /> </Label.GestureRecognizers> </Label>
    It's not working on iOS.

  • sachinJsachinJ INMember ✭✭
    edited June 2017
    <views:SKCanvasView x:Name="canvas"  PaintSurface="OnPaintSample">
                            <views:SKCanvasView.GestureRecognizers>
                                <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />                            
                            </views:SKCanvasView.GestureRecognizers>
                        </views:SKCanvasView>
    

    private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
    }

    using this code how to get tapped portion points using 'e' or sender object ?
    or any other solution to get tapped/clicked portion point.

Sign In or Register to comment.