我正在开发一个小型的Xamarin.Forms Webview应用程序。这是对之前回答的一个问题的追问:xamarin-forms-making-webview-go-back
所以我已经实现并成功使用了一个工具栏和后退按钮。但是当我在模拟器已经开启的情况下运行程序(我使用的是Genymotion),程序会运行并显示出工具栏和后退按钮...但是没有任何Webview内容显示。
但是奇怪的是,有时候当我在模拟器处于睡眠状态时运行程序,然后重新打开模拟器,程序就可以完美地运行。此外,当我在iOS上进行测试时,它只显示工具栏,而没有Webview!更多时候,模拟器不会显示Webview。我还在我的Android设备上进行了测试,结果也一样,会显示工具栏但不会显示Webview。
可能有点令人困惑,但有人能帮我解决这个问题吗?
下面是我的代码: App.cs
但是奇怪的是,有时候当我在模拟器处于睡眠状态时运行程序,然后重新打开模拟器,程序就可以完美地运行。此外,当我在iOS上进行测试时,它只显示工具栏,而没有Webview!更多时候,模拟器不会显示Webview。我还在我的Android设备上进行了测试,结果也一样,会显示工具栏但不会显示Webview。
可能有点令人困惑,但有人能帮我解决这个问题吗?
下面是我的代码: App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace WebView_form
{
public class App : Application
{
public App()
{
//const string URL = "http://www.google.com";
MainPage = new NavigationPage(new WebPage());
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
WebPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace WebView_form
{
public class WebPage : ContentPage
{
private WebView webView;
public WebPage()
{
webView = new WebView
{
Source = "https://www.google.com"
};
// toolbar
ToolbarItems.Add(new ToolbarItem("Back", null, () =>
{
webView.GoBack();
}));
Content = new StackLayout
{
Children = { webView }
};
}
}
}
如果有人能帮我,那就太好了。