Laszlo
Laszlo

Reputation: 63

How can I open page in my Xamarin app without using navigation?

I have a Xamarin Forms application, which has 2 buttons on the toolbar. Currently I'm using FreshMVVM (and it's navigation). I want to load pages without putting them into the navigation. I do not want to have the 'back' button on the toolbar, also I do not want the user return the last page.

Here's how I push a page currently:

CoreMethods.PushPageModel<FirstChoicePageModel>();

I tried to push as a modal, but that way the toolbar buttons does not work until I press back. Should I make new navigation containers and switch to them if I push the buttons?

Upvotes: 0

Views: 522

Answers (2)

Andrew
Andrew

Reputation: 1438

It's been a little while since I've used FreshMVVM, but if I recall correctly, you have 2 options:

  1. If you want to completly reset the nav stack, you can do CoreMethods.PushPageModelWithNewNavigation<FirstChoicePageModel>();
  2. If you want to keep the nav stack, you can set NavigationPage.SetHasBackButton(this, false); in the code behind of the view.

For both of these options, it may necessary to intercept the back button on Android. In the code behind there is an overrideable method:

protected override bool OnBackButtonPressed()
{
    return true; // prevent Xamarin.Forms from processing back button
}

Upvotes: 1

user5652250
user5652250

Reputation:

If you want to show a page, but you doesn't want to navigate (change the current page), you can always use Popups.

See this link https://github.com/rotorgames/Rg.Plugins.Popup

Upvotes: 1

Related Questions