xamarin - MvvmCross iOS SelectedCommand for a custom TableViewCell -


i'm working on mvvmcross app ios in need use custom tableviewcell. know how implement selectedcommand event on mvxsimpletableviewsource. got work mvxstandardtableviewsource , found this solution on youtube. problem solution stuart uses mvxstandardtableviewsource. other problem model want bind selectedchangedcommand not same model bind source to.

i have been searching internet while find answer problem, hope can me this. in advance.

here's code:

mainviewmodel.cs

namespace myapp.core.viewmodels {     public class mainviewmodel : baseviewmodel     {         private navigationlistviewmodel _navigationmenu;         public navigationlistviewmodel navigationmenu     {         { return _navigationmenu; }         set { _navigationmenu = value; raisepropertychanged(() => navigationmenu); }     }      public void init()     {         navigationmenu = new navigationlistviewmodel();         navigationmenu.init();     } } 

navigationlistviewmodel.cs

namespace myapp.core.viewmodels.navigationviewmodels { public class navigationlistviewmodel : baseviewmodel, ipageselectedservice {     private list<navigationitemviewmodel> _navigationlist;     public list<navigationitemviewmodel> navigationlist {          { return _navigationlist; }          set { _navigationlist = value; raisepropertychanged(() => navigationlist); }      }      public void init() {         navigationlist = new list<navigationitemviewmodel> {             new navigationitemviewmodel { displayname = "assortment", actionlink = navigatetocategories },             new navigationitemviewmodel { displayname = "shops", actionlink = navigatetoshops }         };     }      public  icommand navigatetocategories      {         { return new mvxcommand(() => showviewmodel<categorylistviewmodel>()); }     }     public icommand navigatetoshops     {         { return new mvxcommand(() => showviewmodel<storelistviewmodel>()); }     } } 

navigationitemviewmodel.cs

namespace myapp.core.viewmodels.navigationviewmodels {     public class navigationitemviewmodel : mvxviewmodel     {            private string _displayname;         public string displayname         {              { return _displayname; }             set { _displayname = value; raisepropertychanged(() => displayname); }         }          private icommand _actionlink;         public icommand actionlink {              { return _actionlink; }              set { _actionlink = value; raisepropertychanged(() => actionlink); }         }     } } 

mainview.cs

namespace myapp.ios.views  {     public partial class mainview : mvxviewcontroller      {         public new mainviewmodel viewmodel {             { return (mainviewmodel)base.viewmodel; }             set { base.viewmodel = value; }         }          public mainview() : base ("mainview", null)          {         }          public override void viewdidload() {             base.viewdidload();              var set = this.createbindingset<mainview, mainviewmodel>();             var source = new mvxsimpletableviewsource(menutableview, maintablecell.key, maintablecell.key);              menutableview.source = source;             set.bind(source).to(vm => vm.navigationmenu.navigationlist);             set.apply();              menutableview.reloaddata();         }     } } 

maintablecell

namespace myapp.ios.views {     public partial class maintablecell : mvxtableviewcell {         public static readonly uinib nib = uinib.fromname("maintablecell", nsbundle.mainbundle);         public static readonly nsstring key = new nsstring("maintablecell");          public maintablecell(intptr handle) : base (handle) {             this.delaybind(() => {                 var set = this.createbindingset<maintablecell, navigationitemviewmodel>();                 set.bind(titlelabel).to(vm => vm.displayname);                 set.apply();             });         }          public static maintablecell create() {             return (maintablecell)nib.instantiate(null, null)[0];         }     } } 

you add selectedcommand property cell implementation, bind actionlink vm property , execute when user selects cell using code in setselected in https://github.com/slodge/mvvmcross/blob/v3/cirrious/cirrious.mvvmcross.binding.touch/views/mvxstandardtableviewcell.cs

 public icommand selectedcommand { get; set; }       private bool _isselected;       public override void setselected(bool selected, bool animated)     {         base.setselected(selected, animated);           if (_isselected == selected)             return;           _isselected = selected;         if (_isselected)             if (selectedcommand != null)                 selectedcommand.execute(null);     } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -