Vasanth
Vasanth

Reputation: 1710

MtFrame GoBackToAsync pop or navigate back to Nth page without loading N-1 pages

I am using MyToolkit MtFrame class for paging in my WinRT app. I am wondering if there is a way to navigate back to Nth page on the stack without loading intermediate pages.

Lets says, here is how my pages stack looks like:

Page 1 -> Page 2 -> Page 3 -> Page 4 -> Page 5 -> Page 6

Now from "Page 6" if I call MtFrame.GoBackToAsync(Page 2), it pops pages 3-5 and calling its OnNavigatedTo event.

Is there any way I can skip loading of pages 3-5 or alteast make it not call the OnNavigatedTo event for those pages?

Upvotes: 0

Views: 60

Answers (1)

Rico Suter
Rico Suter

Reputation: 11868

This is the way GoBackToAsync is currently implemented. But you could first remove the pages using RemovePageFromStackAt and then only call GoBackAsync:

Assuming you are on page 6 and want to go to page 2, use this code:

frame.RemovePageFromStackAt(Page5);
frame.RemovePageFromStackAt(Page4);
frame.RemovePageFromStackAt(Page3);
await frame.GoBackAsync(); 

Because you removed the pages 3-5 beforehand, GoBackAsync jumps from page 6 to page 2...

But keep in mind: This way the pages are removed forever and forward navigation is broken and should therefore be disabled...

The only clean solution is to implement GoBackToAsync so that it not only calls GoBackAsync multiple times... Please create an issue on the codeplex project for that.

The generic code from @Vasanth:

while (currentView.Frame.PreviousPage != desiredPage) 
{ 
    currentView.Frame.RemovePageFromStackAt(currentView.Frame.CurrentIndex - 1); 
}

Update: In MyToolkit v2.3.29 you can use GoBackToAsync, the problem is now fixed...

Upvotes: 2

Related Questions