TeoVr81
TeoVr81

Reputation: 1009

Image tap event with Xamarin.Forms and Prism

I'm developing a cross platform application with Xamarin. The framework used for MVVM is Prism. In my user interface there is an image, I need that it raise an action when it's tapped. I tried with TapGestureRecognizer but it doesn't work. Where is the error? There is another way to do that?

XAML:

            ...<Frame Grid.Row="0" Grid.Column="0" OutlineColor="Black" Padding="5">
            <Image x:Name="imgSynch" Source="synch.png" >                    
                <Image.GestureRecognizers>
                    <TapGestureRecognizer Command="Binding TapCommand" />
                </Image.GestureRecognizers>
            </Image>
        </Frame>...

ViewModel:

... ICommand tapCommand;

    public ICommand TapCommand
    {
        get { return tapCommand; }
    }
    public MainPageViewModel()
    {                            
        var tapImageSynch = new TapGestureRecognizer();
        tapCommand = new Command(Synch);
    void Synch()
    {
        _pageDialogService.DisplayAlertAsync("Title", "It works!", "OK");
    } ...

Thanks!

Upvotes: 1

Views: 2273

Answers (1)

Luca
Luca

Reputation: 1826

You've got a syntax error in your code:

Command="Binding TapCommand" 

should be:

Command="{Binding TapCommand}"

if your Binding is specified as an instance of MainPageViewMode

Upvotes: 4

Related Questions