在xamarin表單中,具有主細節佈局的RootPage。我的任務是在用戶成功登錄後顯示該頁面。我正在使用azure移動服務進行登錄。我花了更多的時間來獲得結果。我看到了一些其他的解決方案,但這些解決方案並沒有像預期的那樣渲染主細節。最後,我得到了解決方案。如何在運行時更改Xamarin表單中的MainPage?
這裏是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();;
}
}
代碼在登錄頁面
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";
}
}
這是一個問題? –