简体   繁体   English

Xamarin表单-Web视图

[英]Xamarin Forms - Web View

Still trying to get my head around Xamarin Forms (iOS). 仍在努力吸引Xamarin Forms(iOS)。 I am working with the WorkingWithWebView template from the Xamarin Website which mostly works. 我正在使用大部分工作的Xamarin网站上的WorkingWithWebView模板。 But I am having trouble getting it to work when I remove the tab view off the App() class. 但是,当我从App()类中删除选项卡视图时,我很难使它工作。

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;

And when I go to LocalHtmlBaseUrl everything works as expected. 当我转到LocalHtmlBaseUrl时,一切正常。

But what I am wanting to do is load a page straight away without having a tabbed navigation on the bottom. 但是我想做的是立即加载页面,而底部没有选项卡式导航。

So far I have tried to do the following: 到目前为止,我已经尝试执行以下操作:

        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;

        }

At the parentpage = page - I get the error: 父页面=页面上 -我收到错误消息:

Cannot implicitly convert type 'Xamarin.Forms.WebView' to 'Xamarin.Forms.Page' 无法将类型“ Xamarin.Forms.WebView”隐式转换为“ Xamarin.Forms.Page”

So the point of this thesis! 因此,本文的重点! I am just wanting to load that local html code that is specified in htmlSource.Html 我只想加载htmlSource.Html中指定的本地html代码

Thanks 谢谢

Caz 卡兹

your browser needs to be contained within a page 您的浏览器需要包含在页面中

var browser = new BaseUrlWebView();

// do your other browser setup logic here

MainPage = new ContentPage { Content = browser };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM