Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

PopModalAsync() produces InvalidOperation in one situation but not another?

$
0
0

I am working on implementing back navigation from a Master-Detail page.

The MasterDetailPage has a corresponding ViewModel, so has the master and the detail pages. I am using the mvvm helpers from Xamarin.Forms.Labs.
The MasterDetailPage is pushed using Navigation.PushModelAsyn() and I have a button on the MasterPage which will pop it again.
However - the Navigation property is null on both the MasterViewModel and the DetailViewModel (but not on the MasterDetailViewModel).
At first I solved this by using MessagingCenter to send a message from MasterViewModel to MasterDetailModel - which would pop the page. However, the second time this is done an exception is thrown: InvalidOperation, "Operation is not valid due to the current state of the object" (so push, pop, push and then pop -> crash)

This is the callstack:

    System.InvalidOperationException: Operation is not valid due to the current state of the object
      at System.Collections.Generic.Stack`1[Xamarin.Forms.Page].Pop () [0x0000b] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.2.0.207/src/mono/mcs/class/System/System.Collections.Generic/Stack.cs:120
      at Xamarin.Forms.Platform.iOS.Platform+<PopModalAsync>d__d.MoveNext () [0x00000] in <filename unknown>:0
      at --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00034] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs:60
      at PP.MobApp.ViewModels.ClientsViewModel+<ClientsViewModel>c__async1.MoveNext () [0x00022] in /Users/amor/code/pw-repos/PP.MobApp/PP.MobApp/ViewModels/ClientsViewModel.cs:17

Now - I have been looking into why this is happening and fail to understand why.

If I add a property to the MasterViewModel referring to the MasterDetailViewModel and call PopModalAsync directly on that then everything is working fine. So like this:

MasterDetailViewModel.Navigation.PopModalAsync();

Again, sending a message to the MasterDetailViewModel and having it perform: Navigation.PopModalAsync() throws exception.

Anybody have a reasonable explanation?

Thanks in advance,


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>