xamarin - Custom cell is not updating viewmodel when user enters input into cell -


i new mvvmcross(xamarin.ios). so, in wrong direction. if can point me in right direction or point out doing wrong.

i have taken on "customermanagement" , "collection" sample of mvvmcross.

basically trying create settings screen.

i have 1 custom uitableviewcell 1 text field. see code below. "entrytf" iboutleted. "entrytf" binded "firstname" property of model. setting value "firstname" reflecting on ui. if user enter textfield doesn't save model. in short cell not updating viewmodel/model.

please note want keep binding out of cell class. so, can reuse cell other models or fields.

public partial class plainentrycell : uitableviewcell {     public static readonly uinib nib = uinib.fromname ("plainentrycell", nsbundle.mainbundle);     public static readonly nsstring key = new nsstring ("plainentrycell");      public plainentrycell (intptr handle) : base (handle)     {   //            this.delaybind (() => {  //             this.addbindings(new dictionary<object,string> ())  //         });     }      public static plainentrycell create ()     {         return (plainentrycell)nib.instantiate (null, null) [0];     }      public string captiontext {         {             return entrytf.text;         }         set {             entrytf.text = value;         }     } } 

my view model:

public class registerviewmodel: mvxviewmodel {     private registermodel _registermodel;      public registerviewmodel ()     {         _registermodel = new registermodel ();         _registermodel.firstname = "test";     }      public registermodel customer {         { return _registermodel; }         set {             _registermodel = value;             raisepropertychanged ("customer");         }     } } 

model:

public class registermodel:mvxnotifypropertychanged {     private string _firstname;      public string firstname {         { return _firstname; }         set {             _firstname = value;             raisepropertychanged ("firstname");         }     }      public string lastname { get; set; }      public string phonenum { get; set; }      public string email { get; set; }      public string pin { get; set; } } 

tableview source:

public class registertableviewsource: mvxtableviewsource {     registerview _registerview;      public registertableviewsource (uitableview tableview, registerview registerview)         : base (tableview)     {         _registerview = registerview;          tableview.registernibforcellreuse (plainentrycell.nib,             plainentrycell.key);         //tableview.registernibforcellreuse (uinib.fromname ("dogcell", nsbundle.mainbundle), dogcellidentifier);     }      protected override uitableviewcell getorcreatecellfor (uitableview tableview, foundation.nsindexpath indexpath, object item)     {         var cell = tableview.dequeuereusablecell (plainentrycell.key, indexpath);         cell.bind (_registerview, "captiontext customer.firstname");         return cell;         //return (uitableviewcell)tableview.dequeuereusablecell (plainentrycell.key, indexpath);     }      public override nint rowsinsection (uitableview tableview, nint section)     {         return 2;     } } 

update: still not able answer. in above code want bind "entrytf" property of model. want keep binding outside class. so, captiontext property not necessary if can point out direct way of binding "entrytf" not there way of creating bindableproperty xamarin forms? feel mvvmcross matured framework so, why there not solution of kind of simple things.

i love here if there simple/other way of achieving same things.

i have looked mtd didn't find useful custom cell , need amount of learning.

basically trying create settings screen.

take @ using monotouch dialog, mt.d, mvvmcross, use mvvmcross binding monotouch.dialog (lists , commands)

that stackoverflow question/answer started using mt.d mvvmcross. use basic settings screens in applications.

cell isn't updating

i wrote article on using custom cells mvvmcross, see http://benjaminhysell.com/archive/2014/04/mvvmcross-custom-mvxtableviewcell-without-a-nib-file/

i have found easier not use nib files , describe ui in code.

it looks in public partial class plainentrycell : uitableviewcell don't ever bind cell viewmodel. have commented out. try like, while adding http://slodge.blogspot.com/2013/07/playing-with-constraints.html application layout:

 public plainentrycell()         {             createlayout();             initializebindings();         }   uilabel captiontext;   private void createlayout()         {                         selectionstyle = uitableviewcellselectionstyle.none;               accessory = uitableviewcellaccessory.disclosureindicator;                       captiontext = new uilabel();              contentview.addsubviews(captiontext);             contentview.subviewsdonottranslateautoresizingmaskintoconstraints();             const int vpadding = 10;             const int hpadding = 20;             contentview.addconstraints(                  captiontext.attopof(contentview).plus(vpadding),                 captiontext.atleftof(contentview).plus(hpadding),                 captiontext.width().equalto(uiscreen.mainscreen.bounds.width / 2) );   private void initializebindings()         {             this.delaybind(() =>             {                 var set = this.createbindingset<plainentrycell, registerviewmodel();                 set.bind(captiontext).to(vm => vm.captiontext);                                set.apply();             });         }  } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -