In this post, we will see how to resolve Label TapGestureRecognizer works with Tapped, but not with Command
Question: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:
Best Answer:As @GeraldVersluis suggested, you should use
TapCommandfirstly. Also, if you’re using
Shellto navigate through pages, don’t forget to Register the routing for
AppShell.xaml.cs. Here’s the detailed steps below for your reference:
1. Install the
CommunityToolkit.Mvvmpackage in your project.
If you have better answer, please add a comment about this, thank you!