我正在研究一個小的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