C# Xamarin.form设置页第二次未工作
我使用xamarin表单创建新的移动应用程序。我必须创建两个页面登录屏幕和主屏幕。 我从你那里得到样品 但当我创建相同的页面时,我无法进入第二页。它总是停留在登录页面只 在我的android活动代码中C# Xamarin.form设置页第二次未工作,c#,xamarin.android,xamarin.forms,C#,Xamarin.android,Xamarin.forms,我使用xamarin表单创建新的移动应用程序。我必须创建两个页面登录屏幕和主屏幕。 我从你那里得到样品 但当我创建相同的页面时,我无法进入第二页。它总是停留在登录页面只 在我的android活动代码中 public class MainActivity : AndroidActivity, LoginManager { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle
public class MainActivity : AndroidActivity, LoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
// SetPage(App.GetLoginPage(this));
}
#region ILoginManager implementation
public void ShowMainPage()
{
SetPage(App.GetHomePage(this));
}
public void Logout()
{
SetPage(App.GetLoginPage(this));
}
#endregion
}
第二次调用setPage方法,但未替换页面内容。请帮助任何人以下是Android第二个设置页面问题的解决方法。创建第二个接口,而不是在现有活动上使用set page,启动一个新活动,其中OnCreate of the new activity调用set page并完成当前活动 App.cs
public static ILoginManager LoginManager;
public static IAppNavigation SplashManger;
public static Page GetLoginPage(ILoginManager lmanager)
{
LoginManager = lmanager;
return new Page_Login();
}
public static Page GetShowSplashPage(IAppNavigation iSplashNavigation)
{
SplashManger = iSplashNavigation;
return new Page_Splash();
}
Android MainActivity
[Activity(Label = "", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity, IAppNavigation
{
protected override void OnCreate(Bundle bundle)
{
//Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetShowSplashPage(this));
}
public void GetLoginPage()
{
StartActivity(new Intent(this, typeof(LoginActivity)));
Finish();
}
[Activity(Label = "", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class LoginActivity : AndroidActivity, ILoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
}
public void GetMainMenu()
{
StartActivity(new Intent(this, typeof(MainMenuActivity)));
Finish();
}
Android LoginActivity
[Activity(Label = "", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity, IAppNavigation
{
protected override void OnCreate(Bundle bundle)
{
//Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetShowSplashPage(this));
}
public void GetLoginPage()
{
StartActivity(new Intent(this, typeof(LoginActivity)));
Finish();
}
[Activity(Label = "", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class LoginActivity : AndroidActivity, ILoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
}
public void GetMainMenu()
{
StartActivity(new Intent(this, typeof(MainMenuActivity)));
Finish();
}
在iOS中,您不需要做任何特殊的事情,只需实现所有必要的接口,就可以在AppDelegate中使用
iOS AppDelegate
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate, ILoginManager, IAppNavigation
{
// class-level declarations
UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.Init();
window = new UIWindow(UIScreen.MainScreen.Bounds);
window.RootViewController = App.GetShowSplashPage(this).CreateViewController();
window.MakeKeyAndVisible();
return true;
}
public void GetMainMenu()
{
window.RootViewController = App.GetMainMenu().CreateViewController();
window.MakeKeyAndVisible();
}
public void GetLoginPage()
{
window.RootViewController = App.GetLoginPage(this).CreateViewController();
window.MakeKeyAndVisible();
}
Forms框架为您处理导航。您应该使用Xamarin.Forms.Navigation类来管理导航堆栈,并避免在Android项目中使用SetPage,