2016-12-07 100 views
0

仍然试图让我的头绕着Xamarin Forms(iOS)。 我正在与主要工作的Xamarin网站上的WorkingWithWebView模板一起工作。但是,当我从App()类中删除标签视图时,我无法正常工作。Xamarin Forms - Web视图

Tab view (This is what works)

 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 =页面 - 我得到的错误:

Cannot implicitly convert type 'Xamarin.Forms.WebView' to 'Xamarin.Forms.Page'

因此,本文的地步!我只是想加载在指定htmlSource.Html

感谢

CAZ

本地的HTML代码

回答

1

您的浏览器需要包含在一个页面内

var browser = new BaseUrlWebView(); 

// do your other browser setup logic here 

MainPage = new ContentPage { Content = browser }; 
+0

感谢那...我知道一个小问题的位 – Caz1224