我想在我的Xamarin Forms Portable应用程序中截取硬件背面,首先我有登录页面,你必须登录并且它将导航到我的主页2 ..在我的主页2之后,当我点击我的硬件后退按钮...它进入我的登录页面或我之前打开的页面..我想要预防它。任何人都可以解决这个问题.. 这是我的登录页面
public LoginPage()
{
InitializeComponent();
}
public async void LoginBtn_Clicked(object sender, EventArgs e)
{
if (UserName.Text == null || password1.Text == null)
{
DisplayAlert("Alert ! ", "Please Enter UserName Or/Password!", "OK");
}
else
{
string uname = UserName.Text;
string pswd = password1.Text;
LoginService objservice = new LoginService();
LoginTokenModel result = await objservice.GetLogin(uname, pswd);
LoginTokenModel logintokenmodel = new LoginTokenModel();
logintokenmodel.User_Id = result.User_Id;
var Login_Token = result.Login_Token;
int user_Id = result.User_Id;
if (uname == result.User_Nmae)
{
// HomePage2 HOMEPge = new HomePage2();
await Navigation.PushModalAsync(new HomePage2(user_Id));
}
else
{
DisplayAlert("Alert ! ", "Invalid Credentials!", "OK");
}
}
}
答案 0 :(得分:0)
用您的Homepage2替换App的MainPage。 因为你没有回到登录页面,所以你不想在NavigationStack中找到它。
这是我在成功登录时所做的事情:
if (uname == result.User_Nmae)
{
App.Current.MainPage = new HomePage2(user_Id);
}
此外,当用户再次在应用程序属性中输入并检查user_Id是否存在时,您还可以第二次保存此user_Id
,如果它只是导航到Homepage2
Application.Current.Properties["id"] = user_Id;
在App.cs onStart
中if (Application.Current.Properties.ContainsKey("id"))
{
var user_Id = Application.Current.Properties["id"] as string;
MainPage.Navigation.PushModalAsync(new Views.Homepage2(user_Id ));
}
else
{
MainPage.Navigation.PushModalAsync(new Views.Login());
}