Xamarin Forms - Navigation.PopAsync() not working - xamarin

I have a tab page i've set to the main page in xamarin forms:
App.Current.MainPage = new MainPage();
MainPage is a tabbed page:
public partial class MainPage : TabbedPage
{....
Within the tabbedPage there is a content page, which has a button click to load a MasterDetail View:
await Navigation.PushAsync(new AttendMasterPage(new AttendanceViewModel(item)));
This works ok, but the masterdetail view is loaded within the tabbed page. so when i use Navigation.PopAsync(); on the Detail page once finished, nothing happens.
I need the page to go back to the original content page on the tabbed control using a button idealy.
Hope this makes sense, any more info needed please let me know

A MasterDetailPage is designed to be a root page, and using it as a
child page in other page types could result in unexpected and
inconsistent behavior. In addition, it's recommended that the master
page of a MasterDetailPage should always be a ContentPage instance,
and that the detail page should only be populated with TabbedPage,
NavigationPage, and ContentPage instances. This will help to ensure a
consistent user experience across all platforms.
Source: official doc
Please get familiar with the official documentation in order to prevent such problems.

Related

How to Remove page from stack in prism xamarin forms

I have two pages when user open application first page get data ,
I created another page and when click add in first one it navigate to the second page , I want when adding the required data in the second page and click submit first page is removed and created again with the newest data
first page is CustomerAddressesPage and second one is AddNewAddressPage
this is my code
await _navigationService.NavigateAsync("/CustomerAddressesPage/AddNewAddressPage/CustomerAddressesPage");
It got me error
Removing views using the relative '../' syntax while navigating is only supported within a NavigationPage
The error tells you exactly how you can fix the issue.
_navigationService.NavigateAsync("/NavigationPage/CustomerAddressesPage/AddNewAddressPage/CustomerAddressesPage");
This of course assumes that you have registered the base NavigationPage from Xamarin.Forms for Navigation or have a custom NavigationPage that was registered with that key.

MvvmCross v5 Navigation (MvxNavigationService)

I am migrating to MvvmCross 5 and I want to start implementing the navigation change using the MvxNavigationService.
Currently I use custom presenters to do things like navigate to a view then take the previous view out of the hierarchy. I assume I don't need custom presenters with the new navigation service.
Is it possible to do this with the navigation service?
Also I would like to navigate to a view but build up a navigation stack for it.
For example say I have three views
Home Page
Item List Page
Item Details Page
What I would like to do is go from the Home page to the Item Detail Page directly, but when I close the Item Detail Page, the Item List Page would be displayed.
E.g. when I do navigation
Home Page -> Item Details Page
What I really want is the navigation stack to be built as follows
Home Page -> Item List Page -> Item Detail Page
The documentation seems to suggest that using the Uri scheme, this would be possible, but I'm not sure how.
Is this possible, if so is it possible to direct me to an example.

Replace Xamarin forms page without pushasync

I've searched through numerous online posts and can't find a suitable answer for this scenario. It's a pretty common requirement. I have a Xamarin.Forms app with a login page and listing page. When the app is started, the login page is displayed. When they login successfully, I want to display the listing page and prevent them from backing up by clicking on the toolbar back button or the hardware back button.
Change the MainPage
when you start the app you should have
Application.Current.MainPage = new LoginPage();
after login, something like
Application.Current.MainPage = new MyFirstPageAfterLogin();

Xamarin Forms navigating to a MasterDetail Page after a Content Page

I'm creating an app using Xamarin Forms where when a user launches an app for the first time, they are sent to a login page. Once they log in, they're redirected to the MasterPage, which is a MasterDetail Page. However, when I try to navigate to the new MasterDetail Page, I only get the Detail Page, and the button to show the Master Portion is missing. The only thing appearing on the app bar is the title I set. I'm currently going to the MasterPage like this:
App.Current.MainPage = new NavigationPage(new MasterPage())
{
Title = "Welcome " + user.firstName
};
Every other run, this isn't an issue, since when a user opens the app it automatically logs them in and goes right to the MasterPage, except during their first use. However, this is a very important issue for me since it happens the first time a user uses my app and it will be part of their first impression.
When you use a MasterDetailpage, you should not wrap it into a Navigationpage (like your code-example). Because the MasterDetailPage should everytime be on top and not inside a NavigationPage.
To navigate between different pages you should wrap your DetailPage from the MasterDetailPage inside a NavigationPage.
Here some code for clarification:
var view = new MyFirstPage();
Application.Current.MainPage = new MasterPage(view);
And inside the MasterPage constructor, do the following:
public MasterPage(Page detailpage)
{
// Set the master-part
Master = new MasterContentPage();
// Set detail-part (with a navigation page)
Detail = new NavigationPage(detailpage);
}
And after that, you can navigate inside your app with this navigation:
var mdp = Application.Current.MainPage as MasterDetailPage;
await mdp.Detail.Navigation.PushAsync(myNextPage);
I usually create a static helper class AppNavigator to do this stuff.
For further information, look at the MasterDetailPage instructions on the Xamarin developer guides.

wp7 application bar without navigation

My problem is that the application bar is not displayed on a page if I don't use the navigationservice to navigate to that page. My code is : frame.content = page, but I need an application bar. Any help would be appreciated.
After reading your comments to Derek's answer. can't you have the second page be a static empty XAML file with just some sort of container, a ContentPresenter for instance. Then the user generated content could be placed into that instead of a dynamically generated page.
That way, you can just navigate to the page and populate the content, instead of messing with frame's content property directly.
When your page is loaded, what is the value of the ApplicationBar.IsVisible property?
UPDATE: So, I would imagine that the problem is to do with updating the Content property of the PhoneApplicationFrame, rather than navigating to it using the NavigationService. Presumably, under the hood, it's doing whatever is necessary to show the application bar.

Resources