我有以下方法在一个 Xamarin.Forms.ContentPage
连接到一个按钮点击事件
public class LoginPage : ContentPage
{
private Button _loginButton = null;
private Entry _PasswordInput = null;
private Entry _UsernameInput = null;
public LoginPage()
{
_UsernameInput = new Entry { Placeholder = "Username" };
_PasswordInput = new Entry { Placeholder = "Password", IsPassword = true };
_loginButton = new Button
{
Text = "Login",
BorderRadius = 5
}
_loginButton.Clicked += LogIn;
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children =
{
_UsernameInput, _PasswordInput, _loginButton,
},
Spacing = 15
};
}
public async void LogIn(object sender, EventArgs eventsArgs)
{
//do authenticate stuff here
SSO.MyAuthentication client = new SSO.MyAuthentication();
bool isAuthenticated = client.Authenticate(_UsernameInput.Text, _PasswordInput.Text);
if(isAuthenticated)
{
//Push home page to top of navigation stack
Navigation.PushAsync(new HomePage());
}
}
}
在以下代码 Navigation.PushAsync(new HomePage());
行中,我在调试时遇到了以下异常:
在 Android 上不支持 PushAsync,请使用 导航页
如何使用 Xamarin.Forms.NavigationPage
对象解决这个问题?