xamarin - Rotate issue on MVVMCross Android app. Command bindings lost when using dialog theme -
i've been using mvvmcross couple of months , have been impressed far. however, have come across issue have of yet been unable resolve.
i have broken down simple solution can problem can reproduced. issue centres around having button on activity styled in "dialog" theme. when device rotated button command bindings lost , buttons no longer fire commands in view model. odd thing other bindings still working.
to simulate have created solution has
1) simple mvxactivity has 1 button. button opens second activity styled dialog.
2) on second mvxactivity have couple of buttons , edittext , textview control. buttons bound commands on view model , edittext , textview bound properties.
i have tried adding following attribute second activity (as suggested elsewhere) not work.
configurationchanges = android.content.pm.configchanges.orientation | android.content.pm.configchanges.screensize
here second view causing issue. removing theme attribute make work - want dialog theme!:
using android.app; using android.os; using cirrious.mvvmcross.droid.views; namespace rotateissue.views { [activity(label = "myactivity", theme = "@android:style/theme.holo.dialog")] public class secondview : mvxactivity { protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.secondview); } } }
here viewmodel view:
using cirrious.mvvmcross.viewmodels; using system.windows.input; namespace rotateissue.core.viewmodels { public class secondviewmodel : mvxviewmodel { private string _hello = ""; public string hello { { return _hello; } set { _hello = value; raisepropertychanged(() => hello); } } public bool datavalid { { return (_hello.length > 0); } } private mvxcommand _savecommand; public icommand savecommand { { _savecommand = _savecommand ?? new mvxcommand(saveasset); return _savecommand; } } private mvxcommand _cancelcommand; public icommand cancelcommand { { _cancelcommand = _cancelcommand ?? new mvxcommand(cancel); return _cancelcommand; } } public void cancel() { close(this); } public void saveasset() { if (datavalid) { //todo: useful close(this); } } } }
i can provide axml if needed. app targetted @ api level 16.
Comments
Post a Comment