2
votes

As I am using xamarin.forms for my application in android which I have to navigate from one page to another. My question is, if navigating from one page to another page adds it to the navigation stack. For example, If my app has navigation such as Page1 --> Page2 --> Page3 --> Page4 --> Page1 (It behaves like cycle) will it replace Page1 when I navigate to that page on second time or will it be adding it to the stack. Can anyone explain about navigation in a simple way??

EDIT

What I mean by replace means if navigating from one page to another adds it to the stack, Won't it affect the performance of the application if the navigation continues like a loop and keeps on adding it to the stack??

Note: I don't want to go back to previous page, Just want to navigate from one to another continously.

Thanks in advance

3
you can simulate this behavior by using PushModalAsync instead of PushAsync - Sten Petrov
@Sten Petrov can you please briefly explain how does PushModalAsync and PushAsync differs the behavoir of navigation stack. It will be really helpful. - Femil Shajin
PushModal doesn't push to the nav stack, there's no "<Back" button when the target page is shown, so you need to create two sets of transitions for each page to its two neighbors - Sten Petrov
Two sets of transitions means?? - Femil Shajin
see my answer, hopefully it works for you - Sten Petrov

3 Answers

0
votes

Can you try to elaborate on the question a bit more? What do you mean by 'replace'?

It's a stack, so no: the first page1 will not be 'replaced', rather a 'copy' will be in place.

Example:

Imagine a list view with bound data objects. When you click an item, you get to an item details page. Imagine the details page to have previous and next buttons to navigate to other items and you press one. The stack will look like this: ListViewPage -> ItemsPage -> ItemsPage.

0
votes

What you're talking about is CarouselPage

CarouselPage takes several ContentPage children and allows you to swipe sideways to switch the page.

public class App
{
    public static Page GetMainPage ()
    {  
        var carousel = new CarouselPage ();
        carousel.Children.Add (new ContentPage () {
            Title="One",
            Content = new BoxView {
                WidthRequest = 90,
                HeightRequest = 100,
                BackgroundColor = Color.Blue
            }
        });
        carousel.Children.Add (new ContentPage () {  
            Title="TWO",
            Content = new BoxView {
                WidthRequest = 90,
                HeightRequest = 100,
                BackgroundColor = Color.Red
            }
        }); 
        return carousel;
    }
}

Alternatively you can put two buttons (or suitable UI elements) on each page you want to show and use Navigation.PushModalAsync() to navigate to previous/next pages

0
votes

Using this.Navigation.PopModalAsync () before PushModalAsync did the trick for me.

this.Navigation.PopModalAsync ();

Now my application runs smoothly :)