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

只谈情不闲聊 提交于 2019-12-22 18:13:57

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/17407576/mvvmcross-for-monodroid-how-to-bind-to-menu-item-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!