xamarin navigation - how to normally implement navigation between login and masterdetailpage - xamarin

So, how do you normally implement navigation between login page and masterdetailpage.?
I tried few implementation and not really what I am looking for.
So basically, when the login is successful, themasterdetailpage should be the root navigation so if we go back /or pop, we would need to go out of the app. But at the moment, it goes back to the login page.
I tried..
using NavigationPage and InsertPageBefore the mainpage and pop so it is in the root page, but there is a catch because of the navigation tab showing on both loginpage and masterdetailpage (one tab layer for navigationpage and one extra layer of tab for master page in masterdetailpage)
I tried..
just instantiating the App.MainPage as new loginPage() without wrapping in NavigationPage, but I could not find a way to open masterdetailpage
Any help and direction is appreciated cheers,

You have not to add LoginPage to Navigation.
You should
Application.Current.MainPage = new LoginPage();
after login is ok you should
Application.Current.MainPage = new MyMasterDetailPage();

Related

Change MainPage from Content page in Xamarin

I am new to Xamarin. How do I change MainPage from ContentPage. Initially when my App load my MainPage is the LoginPage then after I logged in I want my Master page to be my MainPage. How do I do that?
Curretly I am using navigation.Pushmodalasync it works but I have a different requirement that I need to set my MainPage.
await Navigation.PushModalAsync(new Master());
just reassign it
App.Current.MainPage = new MyPage();

White Screen Issue while navigating in Xamarin forms Prism MasterDetails Page

I have implemented MasterDetail Page using xamarin forms prism and I have following Pages in my app.
1) Master
2) Home
3) Employee
4) Profile
-- Initially App is set to Master - Home (Detail Page) page after login. From Home page i navigate to Employee (Detail Page) using code as follows :
await _navigationService.NavigateAsync("NavigationPage/Employee");
-- From Employee Page I navigate to Profile (Content Page - Non Detail page) by clicking on one of the employees using code:
await _navigationService.NavigateAsync("Profile", lstparam, null, false);
-- Once home button is clicked in profile page, i want to navigate to Master - Home (Detail Page) . However it navigates to Employee (Detail Page) .
await _navigationService.GoBackToRootAsync();
Checked navigation stack by debugging , It was only showing Employee (Detail Page) Page in it. Also tried navigation to home page by using following code :
await NavigationService.NavigateAsync("/Master/NavigationPage/Home");
The above code is working and i can navigate to Home (Detail Page) , but I am getting White Screen while navigating to Profile to Home Page .
Attached Screenshots . Please Help .Thanks in Advance.
MasterPage
Details_Home
Details_Employee
Profile
Whitescreen
I recently had a very similar problem but it did not depend on prism.
I wanted to create an autologin features by bypassing the login (ContentPage) and calling the homepage (Master And Detail Page).
To do this I had to call the async login service method in my application class.
in order:
Call async service
Call NavigationService.NavigateAsync
In this case appears a blank page
To Solve:
Call NavigationService.NavigateAsync
Call async service
In my case, it happened to me for being using the wrong NavigationService.
I had a static Navigator class that I've been using it for managing and Logging navigations in the App (a simple wrapper), which has a property called Instance, of type NavigationService that I was setting it to the NavigationService of the App.xaml.cs
Reassigning it on each ViewModel (in the ViewModelBase's constructor) fixed the white page bug for me.
Hope it helps someone!

How add a back button manually in NavigationPage?

I have a login page in Xamarin.Forms without NavigationPage, but I have a button in this page to navigate to other page to create a new user and, in the page of insert user, I need add a back button to allow users go back to the login page.
How can I do that?
ps: I'm using Prism framework.
My code to open login page:
await NavigationService.NavigateAsync("Login", parametrosNavegacao);
My code to navigate to page that register user:
await NavigationService.NavigateAsync("NavigationPage/CadastroUsuario", useModalNavigation: true);
NavigationService.PopupGoBackAsync();
https://github.com/dansiegel/Prism.Plugin.Popups
One option can be
NavigationService.NavigateAsync("/Login");
the / bebore Login means Absolute url, and prism clears navigation stack, other wise clicking android's back button will again open up insert user page.

Master Detail Page Xamarin Forms

Aright, let me try to make it a bit simple,
When i Login: i set the my root page as a Normal ContentPage,
var firstPage = new BaseNavigationPage(new DashBoardPage());
(DashBoardPage is just a contentPage, with few buttons)
On click of the buttons, i navigate my app, using
NavigationService.NavigateTo(ViewModelLocator.CommentPage);
Now on DashbOard, there is button, which redirects me to a Page which is a MasterDetailPage, so using some custom thing,
i navigate by setting my MasterPage,
NavigationService.SetMainPage(ViewModelLocator.MASTER_PAGE);
Following is my MasterDeatilPAge Code;
var menuPage = new MenuListPage();
Master = menuPage;
Detail = new CustomNavigationPage(new WorkTaskPage());
Now , on the Menu Page, i have an List Item as DashBoard, and i have to redirect my App to the first Page,
So how can i do that, since with MasterDetail Page, i can either Navigate Detail Page or Set the Detail Page,
So how can i redirect it to the Dashboard Page, and i want all navigation to work normally when i am on dashboard page, without changing any navigations.
Hope this is a bit clear?

Refresh Or Update Page on click of back button (WP7)

I have used the standard navigation service in my app but the problem is
Accounts Page (Show info from datacontext) -> Add Accounts Page
now if i give navigation to Accounts Page from Add Accounts Page it creates new instance of Accounts Page as below
Accounts Page (Old Data) -> Add Accounts Page -> Accounts Page (Updated Data)
when i get to the new instance the data on the page shows the new entry but if get back i get to the add accounts page again & then Accounts Page (Old Data) which does not show the updated entryso i have to get back to the home pag & again navigate to Accounts Page to get it updated so what should i do to make Add Accounts Page save button send me back to the Accounts Page & its updated?
I tried with
NavigationService.GoBack();
NavigationService.RemoveBackEntry();
NavigationService.Navigate(new Uri(string.Format("/Accounts.xaml?Refresh=true"), UriKind.Relative));
but nothing worked as i wanted PLEASE HELP
NavigationService.GoBack(); is the right way. The problem you need to focus on is: "how to refresh the data when going back to the Accounts Page". The solution depends on your application's architecture. If you used the MVVM pattern, then it's just a matter of adding the new account to the data source in the viewmodel. Otherwise, you should probably reload the account list in the OnNavigatedTo method of your page:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Load the accounts
}

Resources