Search code examples
xamarin.formsmvvmcross

I have created MasterDetailPage in MvvmCross, the click(Command) is not working on detail page


I have created an mvvm cross application in which I have created a viewmodel as well as a page with xaml.cs. So the view model is not being called from page(xaml) command or the navigation is not working.

I have attached the command :

public IMvxAsyncCommand LblTappedNumberCommand => new 
MvxAsyncCommand(async 
 () =>
    {
        await _navigationService.Navigate<AddPhoneNumberViewModel>();
});

Xaml for above :

  <Image Source="user.png">
  <Image.GestureRecognizers>
  <TapGestureRecognizer Command="{Binding 
  EditProfileClicked}" NumberOfTapsRequired="1" />
  </Image.GestureRecognizers>
  </Image>

By removing MasterDetailPage(sidebar) above code works properly.

When I write a code for click event in xaml.cs like below it works:

xaml.cs :

public void EditProfileClicked(object sender, EventArgs args)
{
    Navigation.PushAsync(new EditProfile1Page());
}

xaml :

<Image  
    HorizontalOptions="End"
    VerticalOptions="End"                  
    Source="user.png">
    <Image.GestureRecognizers>
        <TapGestureRecognizer Tapped="EditProfileClicked" 
NumberOfTapsRequired="1" />
    </Image.GestureRecognizers>
</Image>

Solution

  • If you see there you are binding the command of the image to EditProfileClicked and you should be binding to LblTappedNumberCommand.