To help us fix your issue, please provide the information in the below template.
Navigation parameters aren't being correctly passed in an Forms application when using Master-Detail. Navigation works when navigating from master but attempting to navigate between view models in the details pane doesn't work.
Start with the TestProjects - Forms - MasterDetailExample
Add navigation parameters class
public class CustomParms
{
public string Var1 { get; set; }
}
Add command to Option1ViewModel - this will trigger navigation to Option2ViewModel, passing a parameter
private MvxAsyncCommand goCommand;
public MvxAsyncCommand GoCommand { get {
return goCommand ?? (goCommand = new MvxAsyncCommand(() =>
Navigation.Navigate
}
}
Add button to Option1Page to invoke command
Alter Option2ViewModel to implement IMvxViewModel
public class Option2ViewModel : MvxViewModel, IMvxViewModel
Add Initialize method to Option2ViewModel
public async Task Initialize(CustomParms parameter)
{
Message = parameter.Var1;
await Task.FromResult(0);
}
Run application, select Option1 from menu and then click on button to attempt to navigate to Option2
Application should navigate the details pane to Option2ViewModel/Option2Page and the label on the page should update with the text "Hello World!"
Application navigates the details pane to Option2ViewModel/Option2Page but the label does not *update
Version: 5.0.3
Platform:
The LoadViewModel in MvxPresenterHelpers (MvvmCross.Forms.Presenters) seems to be generating a duplicate view model. Wondering if that's where the issue is??
I have found the same problem, but just on navigation using the new IMvxNavigtionService. I have attached a reproduction.
As @nickrandolph said, a duplicate view model is created, the first one with the details, while the second one does not, resulting in the UI showing the duplicate viewModel without the details.
Please no zip blobs. Make a new repository and chuck in the code there
@Cheesebaron - I've uploaded the reproduction from @willsam100 to https://github.com/jimbobbennett/MvvmCross5BugRepro
I created another repo in case you need it https://github.com/dpalat/App.Template
I have the same problem.
Is there any resolution?
i think the problema is here:
public static class MvxPresenterHelpers
{
public static IMvxViewModel LoadViewModel(MvxViewModelRequest request)
{
var viewModelLoader = Mvx.Resolve<IMvxViewModelLoader>();
var viewModel = viewModelLoader.LoadViewModel(request, null);
return viewModel;
}
...
Alwais recreate VM instance.
I also was hunting this bug in my application and found a bug report on the official Xamarin tracker, so this issue might not be MvvmCross related.
Versi贸n 5.1.0 is ok
Hi guys, I upgraded to 5.1.0 today - and the view model is still instantiated twice.
@BradVause Are you using the NavigationService? This should be fixed in this line: https://github.com/MvvmCross/MvvmCross/blob/develop/MvvmCross-Forms/MvvmCross.Forms/Presenters/MvxPresenterHelpers.cs#L22
@BradVause : I can confirm that the bug is fixed for me in 5.1.0. (using NavigationService)
5.1.1 - The duplication occurs in your example - https://github.com/martijn00/MvxForms
Under Android - start app, "back" to close and start again - the page duplicated.
Most helpful comment
I have found the same problem, but just on navigation using the new IMvxNavigtionService. I have attached a reproduction.
As @nickrandolph said, a duplicate view model is created, the first one with the details, while the second one does not, resulting in the UI showing the duplicate viewModel without the details.
MvvmCross5repro.zip