c# - Passing data from Activity to ViewModel -
i'm newbie using mvvmcross , have issue. want implement taking photo in activity, native way, don't know how can pass data viewmodel.
there way that?
passing data viewmodel easy. if in activity , given inherits mvxactivity or likes have viewmodel
property can access directly it.
there generic versions of these activities, don't have type cast viewmodel
property yourself.
so if have:
public class myactivity : mvxactivity<pictureviewmodel> { }
then can access viewmodel
:
viewmodel.someviewmodelproperty = mydata;
this mydata
object byte array picture data.
mvvmcross have picture taking plugin already, uses built in android camera take pictures with. if add
mvvmcross.plugins.picturechooser
to both android , core project, can use imvxpicturechoosertask
directly in viewmodel
without involving else:
public class pictureviewmodel : mvxviewmodel { private imvxpicturechoosertask _picturetask; public pictureviewmodel(imvxpicturechoosertask picturetask) { _picturetask = picturetask; } private byte[] _picturebytes; // in command: private void dotakepicture() { _picturetask.takepicture(500, 500, stream => { _picturebytes = readstream(stream); }, () => {}); } }
Comments
Post a Comment