我添加了一个公共方法来返回变量 pageLoaded,但 Visual Studio 显示此错误“MainPage.PageLoaded() 方法需要对象引用而不是静态”。逻辑是仅当 pageLoaded 为 true 时才完成 Splash Activiy。如果有人对此有更好的想法,很高兴知道,我刚刚开始学习 C#/Xamarin。
我的代码:
namespace MyApp
{
public partial class MainPage : ContentPage
{
private bool pageLoaded = false;
public MainPage()
{
InitializeComponent();
webnav.HeightRequest = 1000;
webnav.WidthRequest = 1000;
webnav.Source = "https://www.example.com";
}
public void Webnav_Navigated(object sender, WebNavigatedEventArgs e)
{
pageLoaded = true;
}
public bool PageLoaded()
{
return pageLoaded;
}
}
}
代码 2:
...
...
using MyApp;
namespace MyApp.Droid
{
[Activity(Label = "My App", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
while (true)
{
if (MainPage.PageLoaded())
{
SplashScreen.fa.Finish();
break;
}
}
}
}
}
临摹微笑
喵喵时光机
相关分类