c# - MvvmCross Xamarin-Forms Viewmodel return values and back navigation -
it's standard mvvm problem of getting results view-model.
mvvmcross v5's navigation service has brought in nice looking solutions this, i'm having trouble in practice. using xamarin-forms , testing android.
the setup main view button command bound calls second view gets value list.
https://www.mvvmcross.com/documentation/fundamentals/navigation
this page suggests new system using call new view , specify return type/value:
var result = await _navigationservice.navigate<newviewmodeltype, paramtype, resulttype>(param);
which works nicely, in newviewmodeltype return (currently) says:
await _navigationservice.close(this, new resulttype()); // overload isn't there in 5.1
that overload doesn't exist, can use close method of mvxviewmodel base (if anyone's hit issue):
await close(new resulttype());
testing in android emulator works nicely when close using command.
if navigate away new view model button original button greyed out , never receive return value in main view.
i'd able press cancel out, button being disabled / await left hanging problem.
so how should handle this. there nice way return default on navigation? or there clean way intercept command , return default/null?
--
here actual bindings , relevant functions in case i've done dumb. operator here individual, not programming operator. view binding
<button text="{res:translate operator}" command="{binding selectoperatorcommand}" />
view model button command
public imvxcommand selectoperatorcommand => new mvxasynccommand(async () => { var result = await _navigationservice.navigate<operatorselectviewmodel, operator, operator>(_operator); operator = result; // never here if press in next view });
the second view model (select list) init , close command
public override task initialize(operator parameter) { _selectedoperator = parameter; return base.initialize(); } public imvxasynccommand closecommand => new mvxasynccommand(async () => { await close(_selectedoperator); // happy exit way. });
Comments
Post a Comment