2016-03-06 41 views
0

我有一個應用程序,其特點是當您打開應用程序時啓動登錄頁面。一旦進入主頁面,它就會有一個主 - 細節頁面來顯示數據。問題是奇怪的佈局。導航頁面位於主頁面的頂部。就像這樣:enter image description hereXamarin.forms - 登錄頁面導航到主詳細信息頁面有一個奇怪的佈局

這裏是登錄

public partial class LoginPage : ContentPage 
      { 
       public LoginPage() 
       { 
        InitializeComponent(); 
       } 
       async void OnSignUpButtonClicked (object sender, EventArgs e) 
       { 
        await Navigation.PushAsync (new SignUpPage()); 
       } 

       async void OnLoginButtonClicked (object sender, EventArgs e) 
       { 
        var user = new User { 
         Username = usernameEntry.Text, 
         Password = passwordEntry.Text 
        }; 

        var isValid = AreCredentialsCorrect (user); 
        if (isValid) { 
         App.IsUserLoggedIn = true; 
         Navigation.InsertPageBefore (new MainPage(), this); 
         await Navigation.PopToRootAsync(); 
        } else { 
         messageLabel.Text = "Login failed"; 
         passwordEntry.Text = string.Empty; 
        } 
       } 

       bool AreCredentialsCorrect (User user) 
       { 
        return user.Username == Constants.Username && user.Password == Constants.Password; 
       } 
      } 

回答

3

此代碼看起來過於複雜的代碼,我已經看到了類似的模式導致渲染問題Xamarin.Forms:

  Navigation.InsertPageBefore (new MainPage(), this); 
      await Navigation.PopToRootAsync(); 

由於當前頁面已知是導航堆棧中的第一頁也是唯一一頁(根據我所知),這應該足夠了:

  Application.Current.MainPage = new MainPage(); 

如果沒有導航堆棧上唯一的頁面,你會想首先彈出導航堆棧(雖然不是在Android上 - 這會導致問題):

  if (Device.OS == TargetPlatform.iOS) { 
       await Navigation.PopToRootAsync(); 
      } 
      Application.Current.MainPage = new MainPage(); 
+0

THANK YOU!我是找到一個簡單的解決方案,像指揮它,而不是添加導航。有用。 –

相關問題