MvvmCross for MonoDroid - How to bind to Menu Item Click event

mvvmcross, xamarin, xamarin.android

Solution

I don't think you can bind it, as the ActionBar is something that is loaded outside of the XML view. Also it does not expose any C# type of events for clicks on items as they are populated from a menu xml file. However you could in your `SetOnMenuItemClickListener` execute commands when a `MenuItem` is clicked. You can simply execute a command like this:

ViewModel.MyAwesomeCommand.Execute();

Problem

I have an MvvmCross PCL and a related MonoDroid UI project (pattern copied from following Stuart Lodge's excellent N+1 video series). I want to bind the click of an Action Bar menu item to an ICommand in my ViewModel. I've seen this post but an IMenuItem doesn't appear to have a suitable property to bind to. I'm aware of the SetOnMenuItemClickListener method but (and this is no doubt my lack of understanding) don't know how to leverage this to bind a System.Windows.Input.ICommand to it. Also, if this is possible, can it be done in the OnCreateOptionsMenu method of the MvxView as this provides a handle to the Action Bar menu itself?

Original source