【问题标题】:How Do I get a webpage to display inside a tabbed page?如何让网页显示在选项卡式页面内?
【发布时间】:2017-12-04 03:12:34
【问题描述】:

有没有办法将网页显示为标签页?选项卡式页面有 2 个选项卡。一个用于关于,一个用于联系,是否可以将标签页的内容仅作为“www.example.com/about”或“www.example.com/contact”之类的url? 目前,我在标签页上只有一个按钮,可以打开浏览器。代码如下:

  public AboutPage()
    {
        InitializeComponent();
        this.Title = "About";


        StackLayout contact = new StackLayout
        {
            VerticalOptions = LayoutOptions.Center,
            Children = {
            new Label {
                HorizontalTextAlignment=TextAlignment.Center,
                Text = "contact here"
            }
            }
        };
        var browser = new WebView();
        var htmlSource = new HtmlWebViewSource();
        htmlSource.BaseUrl = "http://www.google.com";
        browser.Source = htmlSource;
        Button abtbutton = new Button
        {
            Text = "View about page"
        };
        abtbutton.Clicked += OnAboutBtnClicked;
        this.Children.Add(new ContentPage
        {
            Title = "About",
            Content = browser
        }
        );
        this.Children.Add(new ContentPage
        {
            Title = "Contact",
            Content = contact
        });
    }

    void OnAboutBtnClicked(object sender, EventArgs args)
    {
        Device.OpenUri(new Uri("http://www.google.com"));
    }

【问题讨论】:

    标签: xaml xamarin webview code-behind tabbedpage


    【解决方案1】:

    我认为您需要两个 webView。

    var browser = new WebView();
    browser.Source = new UrlWebViewSource { Url = "https://developer.xamarin.com/" };
    this.Children.Add(new ContentPage
    {
        Title = "About",
        Content = browser
    }
    );
    
    var browser2 = new WebView();
    browser2.Source = new UrlWebViewSource { Url = "https://stackoverflow.com/" };
    this.Children.Add(new ContentPage
    {
        Title = "Contact",
        Content = browser2
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多