我正在研究一个小的Xamarin.Forms webview应用程序。这是以前回答的一个后续问题,xamarin-forms-making-webview-go-backXamarin Forms - Webview没有显示
所以我有一个工具栏和一个后退按钮的实现和工作。但是当我用已经打开的模拟器(即时使用Genymotion)运行程序时,该程序将运行并显示工具栏以及后退按钮...但是不会显示webview。
但是继承人的奇怪的事情,有时当我运行程序,当模拟器处于睡眠模式,然后切换回程序完美工作。另外,当我在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 }
};
}
}
}
如果有人能帮助我,这将会是大。
工作!谢谢:) – Duggan