I was recently browsing stackoverflow.com and ran across a question asking about commands using Xamarin.Forms. I decided to do a quick tutorial to explain what you need to know when you use commands and Xamarin.Forms.
For this example I decided to use MVVMLight since it provides a lot of the boiler plate code but any modern MVVM framework should do the trick. The stackoverflow question I mentioned was about passing parameters using Commands. The code sample provided in the question attempts to use an event handle in order to invoke a command but events are a completely different beast. The main difference between events and commands is that commands can be canceled while events cannot.
As I was saying you need an MVVM framework that supports generics in order to support parameter passing of a certain type. Since MVVMLight is open source you can see an example of this here. As you can see, the generic version of ICommand allows you to pass in the TYPE of property you want to pass along with it.
Now lets get into the code!
I first created a standard Xamarin Forms project using Xamarin Studio. It should be pretty straight forward if you go through their new project creation wizard. Make sure you include the MVVMLIght libraries if you wish to follow my example.
My page just consists of an Entry field to enter a ToDoItem, an add button, and a listview that will list the ToDoItems. These controls contain bindable properties that can be set using the ViewModel posted below.
I also created a View Modal that contains my command which adds to the todo items list.
I created a TodoTitle property that implements INotifyPropertyChanged. I'm using a helper method created by MVVMLight to quickly accomplish this. I also created a RelayCommand with the TYPE of string. This will allow us to automatically cast the parameter to its appropriate type. Since the RelayCommand takes and action as its parameter, you can simply pass in your method into the constructor.
As you can see in the Xaml, I have bounded the TodoTitle to the button as the CommandParameter. This allows me to pass along the text string through the RelayCommand which then gets passed down to my method to do what I want with it. Now you have a fully functioning Todo list! To browse the full code please visit my github account here.