【发布时间】:2016-12-08 07:07:30
【问题描述】:
仍在尝试了解 Xamarin Forms (iOS)。 我正在使用 Xamarin 网站上的 WorkingWithWebView 模板,该模板大部分都有效。但是当我从 App() 类中删除选项卡视图时,我无法让它工作。
选项卡视图(这是有效的)
var tabs = new TabbedPage ();
tabs.Children.Add (new LocalHtml {Title = "Local" });
tabs.Children.Add (new LocalHtmlBaseUrl {Title = "BaseUrl" });
tabs.Children.Add (new WebPage { Title = "Web Page"});
tabs.Children.Add (new WebAppPage {Title ="External"});
MainPage = tabs;
当我转到 LocalHtmlBaseUrl 时,一切都按预期工作。
但我想做的是立即加载页面,而底部没有选项卡式导航。
到目前为止,我已尝试执行以下操作:
public App ()
{
//var tabs = new TabbedPage ();
//tabs.Children.Add (new LocalHtml {Title = "Local" });
//tabs.Children.Add (new LocalHtmlBaseUrl {Title = "BaseUrl" });
//tabs.Children.Add (new WebPage { Title = "Web Page"});
//tabs.Children.Add (new WebAppPage {Title ="External"});
//MainPage = tabs;
var parentpage = new Page();
var page = new WebView();
var browser = new BaseUrlWebView(); // temporarily use this so we can custom-render in iOS
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html>
<head>
<link rel=""stylesheet"" href=""default.css"">
</head>
<body>
<h1>Xamarin.Forms</h1>
<p>The CSS and image are loaded from local files!</p>
<img src='XamarinLogo.png'/>
<p><a href=""index.html"">next page</a></p>
</body>
</html>";
htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
browser.Source = htmlSource;
page = browser;
parentpage = page;
MainPage = page;
}
在 parentpage = page - 我收到错误:
无法将类型“Xamarin.Forms.WebView”隐式转换为 'Xamarin.Forms.Page'
所以这篇论文的重点!我只想加载 htmlSource.Html
中指定的本地 html 代码谢谢
卡兹
【问题讨论】:
标签: c# ios xamarin.ios xamarin.forms