android - Mvvm cross binding data context -


i trying implement mvvm cross solution. facing issue bindings..

i trying implement solution in xamarin.android.

below main layout page - main.axml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:local="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">     <textview         local:mvxbind="text title/>     <mvx.mvxlistview         android:id="@+id/srmtypelist"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:fastscrollenabled="true"         local:mvxitemtemplate="@layout/list_item"         local:mvxbind="itemssource personcollection" /> </linearlayout> 

below view model:

public class mainviewmodel :mvxviewmodel {     private string title;      public string title     {         get{ return title;}         set         {             title = value;              raisepropertychanged (()=> title);         }     }      list<person> _personcollection;            list<person> personcollection     {         { return _personcollection; }         set         {             _personcollection = value;            raisepropertychanged (() => personcollection);         }      public mainviewmodel()     {          _personcollection = new list<person>();         personcollection.add(new person{name="steve", salary=10000});         personcollection.add(new person{name="mary", salary=20000});     } } 

mainview.cs

protected override void oncreate (bundle bundle) {      base.oncreate (bundle);      setcontentview (resource.layout.main); } 

the issue starts here in item template list view in main screen list_item.axml shown below:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:local="http://schemas.android.com/apk/res-auto"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent">      <checkbox         android:id="@+id/checkbox2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         local:mvxbind="?" />      <textview         android:textcolor="#fff"         android:textsize="16sp"         local:mvxbind="?"/> </linearlayout> 

how make binding textview's text , checkbox parent's view model (ie. in main view model class)?.

any pointer/ solve highly appreciated.

i have gone through below links .. being newbie not able understand implementation.

binding button click in listview template mvvmcross

mvvmcross changing viewmodel within mvxbindablelistview

i not able understand how create wrapper class , how set data context of item template (list_item.axml) wrapper class. way in mvvm cross can refer bindings in item template directly parent view model in case mainviewmodel.

can kindly post simpler example?

i'm not sure if that's asking, make binding of person's name listitem textview:

local:mvxbind="text name" 

and instead of using list should use observablecollection

observablecollection<person> _personcollection;        observablecollection<person> personcollection {     { return _personcollection; }     set     {         _personcollection = value;        raisepropertychanged (() => personcollection);     } 

}

for checkbox add field person class such isselected , bind checkbox:

 local:mvxbind="checked isselected" 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -