Friday, March 13, 2015

MVVMCross iOS: How to trigger RowSelected Table View?

I was struggling with how to raise an MVVM event on a click within a tableview.
Fortunately, Stuart Lodge has come through with a great demo of how this all works.
His N+17 video about 47 minutes in gives the details for iOS.  He also has a demo
in his MVVM samples library.  I lifted the pertinent code out of the repo.  The key is to bind
your MVVM command to the SelectionChangeCommand which is a property of the TableView
row item.

Sample:

ModelView:

new Cirrious.MvvmCross.ViewModels.MvxCommand<DilbertItem>((dilbertItem) =>
{   
// note that we can only pass an id here - do *not* serialiase the whole dilbertItem ShowViewModel<DilbertDetailViewModel>(new { id = dilbertItem.Id });
});


View:

// binding
set.Bind(source) .For(s => s.SelectionChangedCommand) .To(s => s.ShowDetailCommand);



Source:
N=17 https://www.youtube.com/watch?v=h0Eww89c9DM&feature=youtu.be&t=47m30s

http://stackoverflow.com/questions/17712589/mvvmcross-ios-how-to-trigger-rowselected-on-a-custom-tableviewsource-using-crea

No comments:

Post a Comment