【发布时间】:2015-12-17 09:01:38
【问题描述】:
我正在开发一个小型 Xamarin.Forms webview 应用程序。这是之前回答的问题的后续问题,xamarin-forms-making-webview-go-back
所以我有一个工具栏和一个后退按钮实现和工作。但是当我在模拟器已经打开的情况下运行程序时(我使用 Genymotion),程序运行并显示工具栏以及后退按钮......但不会显示 webview。
但奇怪的是,有时当我在模拟器处于睡眠模式时运行程序然后将其重新打开时,程序运行良好。另外,当我在 iOS 上测试它时,它只显示了工具栏,根本没有 webview!通常情况下,模拟器不会显示 webView。我也在我的 Android 设备上对此进行了测试,并且发生了同样的事情,它会显示工具栏而不是 web 视图。
我知道有点困惑,但任何人都可以帮助我解决这个问题。
我将在下面附上我的代码:
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 }
};
}
}
}
如果有人可以帮助我,那就太好了。
【问题讨论】:
标签: c# xamarin xamarin.forms xamarin-studio