I have a CrossPlatform App and did not test the other plattforms, only UWP yet.
Windows 10 with Xamarin Forms 3.1.0.697729 which was one installed for CrossPlattform.
The structure of my pages has been changed to the following:
<NavigationPage>
<ContentPage>
<Stacklayout or some other Content>
I have a Stack with at least one of those pages. Naming the Pages A (Top of Stack (Modal)) B (App Main Window, normally to show after PopModalAsync or also on stack) and C (new Window)
After returning from Page A (with "PopModalAsync") should NOT show up Page B instead of the new Page C instead.
I found a lot of similar examples, here in the forum, on Microsoft pages directly, on stackoverflow telling me two options:
(1)
A.Navigation.InsertPageBefore(C, A);
await Navigation.PopModalAsync();
or
(2)
await Navigation.PushModalAsync(C);
C.Navigation.RemovePage(A);
None of the both worked as expected. Both are terminating with an "System.ArgumentException".
First case (1) comes up like that:
System.ArgumentException
HResult = 0x80070057
Nachricht = before must be a child of the NavigationPage
Quelle = Xamarin.Forms.Core
Stapelüberwachung:
bei Xamarin.Forms.NavigationPage.InsertPageBefore (Page page, Page before)
bei Xamarin.Forms.NavigationPage.NavigationImpl.OnInsertPageBefore (Page page, Page before)
bei Xamarin.Forms.Internals.NavigationProxy.InsertPageBefore (Page page, Page before)
bei ZZZZ.Pages.ProgressAndCancelDialog.d__28.MoveNext () in C: \ ZZZZZ \ Pages \ ProgressAndCancelDialog.cs: Zeile197
Second case (2) comes up like that:
System.ArgumentException
HResult = 0x80070057
Nachricht = Page to remove must be contained on this Navigation Page
Quelle = Xamarin.Forms.Core
Stapelüberwachung:
bei Xamarin.Forms.NavigationPage.RemovePage (Page page)
bei Xamarin.Forms.NavigationPage.NavigationImpl.OnRemovePage ( Page page)
bei Xamarin.Forms.Internals.NavigationProxy.RemovePage (Page)
bei ZZZZ.Pages.ProgressAndCancelDialog.d__28.MoveNext () in C: \ ZZZZZ \ Pages \ ProgressAndCancelDialog.cs: Zeile198
I have no idea how to solve that issue. The first solution would be better, because of the triggered events are more similar, but I could solve it the second way. Before using the Page-Structur shown above, I did not use the NavigationPage. I added it only because of other Exceptions, which told me it's impossible using InsertBeforePage or RemovePage with other pages than NavigationPage.
When modifing case (1) like that:
(1A)
NavigationPage P = new NavigationPage(A);
P.Navigation.InsertPageBefore(C, A);
await Navigation.PopModalAsync();
The Insert works without exceptions but now the PopModalAsync () crashes like that:
System.ArgumentOutOfRangeException
HResult = 0x80131502
Nachricht = Index was out of range. Must be non-negative and less than the size of the collection.
Quelle = System.Private.CoreLib
Stapelüberwachung:
bei System.ThrowHelper.ThrowArgumentOutOfRange_IndexException ()
bei Xamarin.Forms.Internals.NavigationProxy.PopModal ()
bei Xamarin.Forms.Internals.NavigationProxy.OnPopModal (Boolean animated)
bei Xamarin.Forms.Internals. NavigationProxy.PopModalAsync (Boolean animated)
bei Xamarin.Forms.Internals.NavigationProxy.OnPopModal (Boolean animated)
bei Xamarin.Forms.Internals.NavigationProxy.PopModalAsync ()
bei ZZZZ.Pages.ProgressAndCancelDialog.d__28.MoveNext () in C: \ ZZZZZ \ Pages \ ProgressAndCancelDialog.cs: Zeile201
After looking at the details, it becomes more clear. The ModalStack is empty after insertPageBefore, but the normal stack has the two pages as i wanted them to be.
[0] {ZZZZ.Forms.ZZZZContentPage} Xamarin.Forms.Element {ZZZZ.Forms.ZZZZContentPage}
[1] {ZZZZ.Pages.ProgressAndCancelDialog} Xamarin.Forms.Element {ZZZZ.Pages.ProgressAndCancelDialog}
where ZZZZContentpage inherits now from NavigationPage and is my Page C, the other Page A.
Using an other modification
(1B)
NavigationPage P = new NavigationPage(A);
P.Navigation.InsertPageBefore(C, A);
await Navigation.PopAsync();
has the advantage of not crashing! But both stacks are now empty at the end of the pop-method, which is not expected and the window is still showing.
Even if Windows C would show up correctly then I would not use PopModalAsync to leave from page C, what I normally do. May be, the use of "Modal" is not necessary at all. I never understood the difference well. How should the user change back to another page in the stack, if the pages are all "Fullscreen" and there are no buttons to change pages without that i am offering and the "back" button which is ever there. Changing all away from "Modal" is some more trial to solve the issue. May I have to make it.
Thank you in advance for any hints or suggestions.
PushAsync
and PopAsync
API to show or dismiss pages. I guess maybe you used a PushModalAsync
to show your page A, then page A wasn't in a Navigation Stack. So InsertPageBefore
failed. If you still need help regarding Xamarin Integration Services feel free to contact me.