How to navigate pages without navigation stack in master detail page? - c#

I've created a PCL project where I'm having a main page where the person can navigate to three sections and each seciton has a login page. After logging in the master detail page comes which has number of pages to navigate.
Navigation Page
Main Page (can be popped)
Login (can be popped)
Master Page
Detail Page
Navigation Page
SubPages
When I'm navigating to detail pages, then it shows the error that android can't have two navigation stacks. How should I navigate to master page without navigation page or what should I do?

You can directly set the MainPage of the App class when you are showing your main page or login page, and wrap your detail page in NavigationPage.
//show main page
MainPage = new MyMainPage();
//show login page
MainPage = new LoginPage ();
//show master detail
MainPage = new MyMasterDetailPage
{
MasterPage = new MyMasterPage()
DetailPage = new NavigationPage(MyDetailPage)
}

Related

How to close multiple contentpages in Xamarin

I developed two ContentPages to let user choose Country and City.
My application starts with Navigation Page:
MainPage = new NavigationPage(new Views.InfoViews.OnBoarding());
OnBoarding page redirects Country selection page and country selection page redirects city selection page like below:
Navigation.PushAsync(new LocationSelector(0));
I want to return onboarding page after place selection.
How can i do that?
to return to the first page in your navigation stack
Navigation.PopToRootAsync();

Show new Page from a button in a Detail Page

I have a MasterDetailPage. I can add a page from my "Menu" and it is content inside the master page. When I want to do the same but with a button from my "FirstMasterPage" it show the Page but over the MasterDetailPage
I tried to create a new MasterPage but not showing nothing
This is the action of the button of one of my pages
Navigation.PushModalAsync(new Pagina_Dos());
I also tried this, but showing nothing. Pagina_Master is my MasterDetailPage
MasterDetailPage mdp = new Pagina_Master();
mdp.Detail.Navigation.PushModalAsync(new Pagina_Dos());
mdp.IsPresented = false;
I want to show my content Page (Pagina_Dos) inside my Master Detail Page, when is clicked from the button. Because from the menu of course its working
first you need a reference to the current MasterDetailPage
var mdp = (MasterDetailPage)App.Current.MainPage;
then you can use the Detail's Navigation property to push a new page
mdp.Detail.Navigation.PushAsync(new Pagina_Dos());

Open page without back or close

I'd like to redirect user to the main page after successful login, so I don't want him to have a back button or be able to get to the login page again.
I have redirected user to the login page with something like this:
if (isAuthenticated)
{
MainPage = new General.Pages.MainPage();
}
else
{
MainPage = new Account.Pages.Login();
}
I'm using this code for successful login, which doesn't work and gives an exception:
await Navigation.PopAsync(false);
await Navigation.PushAsync(new General.Pages.MainPage());
The given exception is:
System.InvalidOperationException: PopAsync is not supported globally on Android, please use a NavigationPage.
And no need to mention that the mentioned NavigationPage doesn't work neither.
I just figured it out, you can change MainPage at any point using this code:
App.Current.MainPage = new General.Pages.MainPage();
I leave this post to be, if it can possibly help other users.
There are 2 ways you could approach this.
Set you App.MainPage initially in the constructor of App.cs as your home page. Then in your home page's OnAppearing event or if it has a ViewModel then its Initialising method check if user is authenticated. If yes load his data. If not the show your Login page as a Modal. Once login is successful, you can pop the modal of login page and load the data for the home page. Also if required you can handle the back button event in the login page to not allow the user to go out of the modal page.
Drawback - The home page would be visible for a second before the login modal shows up.
In the constructor of App.cs check if the user is authenticated. If user is authenticated then show home page by setting it as the MainPage. Else set the MainPage as login page. Once login is successful again set the MainPage.
Drawback - Checking isAuthenticated in the constructor might make the initial load of the application seem slower.
And for the error you encounter is because you did not push any pages into the navigation stack. Hence your pop wont work.
var firstPage = isAuthenticated ? new General.Pages.MainPage() : new Account.Pages.Login();
MainPage = new NavigationPage(firstPage);
If you will use
mentioned NavigationPage
properly, PopAsync will work.

How to Navigate from Tab Page to Normal WPF Page

I have four tab pages in Tab controller. I wish to navigate from a tab page to Normal WPF page. For that I am using this.NavigationService.Navigate(new Page1()); . I am able to navigate to new page that is Page1 but the tab control is still there. Seems Like only stack panel is getting replaced. Is there any way to do it correctly?
You are calling the Navigate method on the ListBox, so only that control is replaced. By setting the MainWindow's Content, only the new Page will be displayed:
Application.Current.MainWindow.Content = new Page1();

How to get access to an active Page in Silverlight 4?

Quick question.. I'm trying to access a UI control, on a specific Page that is loaded on startup, by using JavaScript.
My MainPage uses a Frame to show a specific Page. From App.xaml.cs I'd like to access an UI control on this specific Page.
Accessing the MainPage is do-able:
MainPage m = (MainPage)Application.Current.RootVisual;
m.testField.Text = "Working!";
But how can I access the Page that is loaded into the Frame on the MainPage.xaml.cs?
Kind regards,
Niels
Hope this helps..
MainPage page = Application.Current.RootVisual as MainPage;
LoadedPage myPage = page.frame.Content as LoadedPage;

Categories

Resources