Turn any Event into a Command in Xamarin.Forms (MVVM All The Things)
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking how to bind a control event like ItemTapped or ItemSelected to a ViewModel command in Xamarin.Forms.
Recommended by 2 people across 2 different months, 2021 to 2022.
What it is
A 14-minute tutorial by James Montemagno, the last in his series on fully applying MVVM to a Xamarin.Forms ListView. It shows how to use the Xamarin Community Toolkit's event-to-command behavior so UI events such as item selection or taps call a simple Command in the view model instead of code-behind handlers.
What people said
Recommends Pelin Konaray · 2021-04 · Stack Overflow · on “Xamarin.Forms Tapped event, no bindable property”
You can't bind OnItemTapped event with this way. you can use Xamarin Community Toolkit ItemTappedEventArgsConverter [LINK] This video also explains [this video] how to use it in a good way.
Recommends user9207271 · 2021-05 · Stack Overflow · on “How to turn Event into Command in Xamarin Forms MVVM”
Tools: I am using Xamarin forms & MVVM I am following video: [this video] NuGet: I have installed NuGet > xamarin.community.toolkit Error: System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.' Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code). Debug: I am trying to Convert Collection ItemSelect Event Into a Command. I know issue is def with code that is trying to convert event to command But I am not sure how to go about debugging this error. Since app has entered in break state, I can't simple add break points. I did copy/paste outfile at bottom
Cites ThisQRequiresASpecialist · 2022-12 · Stack Overflow · on “Xamarin Forms: How to send object and event through to ViewModel on ImageButton Clicked using Commands”
I've created a CustomElementTagger class which allows me to set and get custom set tags on view elements. I need this because I want to have a single command that gets executed but has different behavior on the corresponding tag on the element. In the ViewModel I want to receive the tag and work with it accordingly but the Command never executes. I've also tried it as an Object but the object never comes back as I need it and when I try to cast the Object to the ImageButton I get an error that I cannot cast this Object . I've looked up youtube videos by JamesMontemagno [this video] but everything I look at that is using EventToCommandBehaviour are ListViews with EventName = "ItemSelected" . Also