Resolved: Label TapGestureRecognizer works with Tapped, but not with Command

In this post, we will see how to resolve Label TapGestureRecognizer works with Tapped, but not with Command


I have followed James Montemagno’s excellent .Net MAUI for Beginners series. In it, he uses a TapGestureRecognizer Command to go to a detail page for the item tapped. I downloaded his repo and tested and it works fine in VS 2022 v17.4.0 Preview 1.0.
I pretty much copied his code directly into mine and it doesn’t work in my project for some reason. Now Tapped does work fine and goes to a new page, but when I use that method it wants me to pass in the view model, which I can’t figure out. So I thought James’ Command method might work better, but can’t get it to even call the TapCommand code – nothing happens when clicking/tapping on the label.
So Edit Profile works. Edit Account does not. Here’s the code:
Code behind:
View Model:
And here’s the constructor for the EditAccount page:

Best Answer:

As @GeraldVersluis suggested, you should use TapCommand firstly. Also, if you’re using Shell to navigate through pages, don’t forget to Register the routing for EditAccount page in AppShell.xaml.cs. Here’s the detailed steps below for your reference:
1. Install the CommunityToolkit.Mvvm package in your project.
2. UserSettings.xaml:
3. ViewModel for the UserSetting Page:
4. Register the routing:

If you have better answer, please add a comment about this, thank you!