How to change MainPage in xamarin formats at runtime?

In forms xamarin, RootPage with the layout of the main layouts. My task is to display this page after a user has successfully logged in. I am using azure mobile service to login. I spend more time to get the result. I saw some other solutions, but this solution does not display the main details as expected. Finally, I got a solution.

Here is the code in app.cs

public App() { Client = new MobileServiceClient("your azure url", "your master key"); LoadMainPage(); } public void LoadMainPage() { if (Client.CurrentUser == null) { MainPage=new NavigationPage(new SplashPage()); } else { MainPage = new RootView();; } } 

On the login page

  async void OnLoginClicked(object sender, EventArgs args) { MobileServiceUser user; try { user = await DependencyService.Get<IMobileClient>().LoginAsync(MobileServiceAuthenticationProvider.Facebook); Application.Current.MainPage=new RootView(); await Navigation.PopToRootAsync(); } catch (InvalidOperationException ex) { if (ex.Message.Contains("Authentication was cancelled")) { //messageLabel.Text = "Authentication cancelled by the user"; } } catch (Exception ex) { // messageLabel.Text = "Authentication failed"; } } 
0
source share
1 answer

You need to look at the navigation without changing the routes for these paths. Take a look at the Xamarin Navigation docs here: https://developer.xamarin.com/guides/cross-platform/xamarin-forms/getting-started/introduction-to-xamarin-forms/#Navigation

 await Navigation.PushModalAsync(new LoginPage()); 
+4
source

All Articles