c# - Passing Parameter From Main to Detail in MVVMCross -
i trying pass selected item list detail view, myitem
null in detailviewmodel
though not in myviewmodel
.
myviewmodel.cs
public virtual icommand itemselected { { return new mvxcommand<myviewmodel>(item =>{selecteditem = item;}); } } public myviewmodel selecteditem { { return _selecteditem; } set { _selecteditem = value; // myitem not null here!!! showviewmodel<mydetailviewmodel>(new { date = date, myitem = _selecteditem }); raisepropertychanged(() => selecteditem); } }
mydetailviewmodel.cs
public class mydetailviewmodel: mvxviewmodel { private myviewmodel _myitem; public void init(datetime date, myviewmodel myitem = null) { // myitem null here!!! _myitem = myitem; } }
you can use parameter object, because can pass 1 parameter. crate nested class parameter
this.
public class mydetailviewmodel: mvxviewmodel { private myviewmodel _myitem; public class parameter { public datetime date {get; set; } public string name {get; set;} } public void init(parameter param) { name = param.name; } }
and show viewmodel like:
showviewmodel<mydetailviewmodel>(new mydetailviewmodel.parameter { date = date, name = _selecteditem.name });
but aware!
the paramters cannot complex due platform issues. might have pass id
of item within parameter
object , load myitem
in init function. or pass string , use serialization: https://stackoverflow.com/a/19059938/1489968
Comments
Post a Comment