2016-12-07 98 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