【问题标题】:Xamarin Forms - Web ViewXamarin 表单 - Web 视图
【发布时间】: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


    【解决方案1】:

    您的浏览器需要包含在页面中

    var browser = new BaseUrlWebView();
    
    // do your other browser setup logic here
    
    MainPage = new ContentPage { Content = browser };
    

    【讨论】:

    • 谢谢你...我知道的一个菜鸟问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 2019-06-30
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多