Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Unable to use TapGestureRecognizer in Xaml

$
0
0

Hello,

I'm trying to use a TapGestureRecognizer on an Image in Xaml. This looks like this:

<StackLayout Orientation="Vertical">
    <Label Text="{Binding PositionString}" FontSize="18" />
    <Label Text="{Binding ZoomString}" FontSize="18" />

    <Image x:Name="image" Source="http://www.jpl.nasa.gov/spaceimages/images/mediumsize/PIA17011_ip.jpg">
        <!--
        TODO FIX: This doesn't work in xaml, but in code. Strange...
        -->
        <Image.GestureRecognizers>
            <TapGestureRecognizer Command="TapCommand" />
        </Image.GestureRecognizers>
    </Image>
</StackLayout>

And the corresponding ViewModel:

public ICommand TapCommand { get; set; }

public MicroscopePageViewModel (Document document)
{
    this.Document = document;

    this.Position = new Point (0.0, 0.0);
    this.Zoom = 0.0;

    this.TapCommand = new RelayCommand (() => Console.WriteLine ("Tap"));
}

Unfortunately that doesn't work. There is no exception shown, xamarin studio just shows a call stack that ends in an unhandled internal exception:

System.Diagnostics.Debugger.Mono_UnhandledException_internal () in 
System.Diagnostics.Debugger.Mono_UnhandledException (ex=) in 
object.8e621870-3969-4aa2-bcd0-7fcde7b90f96 (Parameters=) in 
System.Runtime.CompilerServices.AsyncVoidMethodBuilder.AnonymousMethod__0 (Parameters=) in 
Android.App.SyncContext.Post.AnonymousMethod__0 (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/38ac51a9/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
Java.Lang.Thread.RunnableImplementor.Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/38ac51a9/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
Java.Lang.IRunnableInvoker.n_Run (Parameters=) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/38ac51a9/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:71
object.8e621870-3969-4aa2-bcd0-7fcde7b90f96 (Parameters=) in 

I also tried to add the TapGestureRecognizer via C# Code and it works fine:

var tapGestureRecognizer = new TapGestureRecognizer ()
{ 
        Command=(this.BindingContext as MicroscopePageViewModel).TapCommand 
};
this.image.GestureRecognizers.Add (tapGestureRecognizer);

Is there anything wrong with my xaml? Or has someone similar problems?
I tested on Android Tablet and Emulator.

UPDATE:
The problem seems to appear in Debug mode only. It works fine in Release mode.

Thanks in advance.
Sören


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>