簡體   English   中英

如何通過單擊xamarin形式的按鈕來打開網頁

[英]How to Open a web page with the click of a button in xamarin form

我有一個xamarin格式的文件稱為HomePage,它從用戶那里獲取eURL內容。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace zaposta_angelar
{
    public class HomePage : ContentPage
    {
        Label lTitle;
        Entry eURL;
        Button bButton;

        public HomePage()
        {
            lTitle = new Label
            {
                Text = "WELCOME",
                HorizontalOptions = LayoutOptions.Center,
                FontAttributes = Font.SystemFontOfSize(25, FontAttributes.Bold).FontAttributes,
                 FontSize = Font.SystemFontOfSize(25, FontAttributes.Bold).FontSize,
                //WidthRequest = 200,
                HeightRequest = 100
            };

            eURL = new Entry { Placeholder = "Enter Site URL", };

            bButton = new Button { Text = "ENTER", };
            bButton.Clicked += bButton_Clicked;

            this.Content = new StackLayout
            {
                Children = {
                    lTitle, eURL, bButton
                }
            };
        }

        void bButton_Clicked(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(eURL.Text)) { DisplayAlert("URL", "Your URL is Empty", "OK"); }
            else
            {
                SitePage.LoadRequest(new SitePage(eURL)));
            }
        }
    }
}

並通過單擊按鈕bButton打開eURL,並將網站加載到另一個名為SitePage的頁面中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace zaposta_angelar
{
    public class SitePage : NavigationPage
    {
        private Entry eURL;

        public SitePage()
        {

        }

        public SitePage(Entry eURL)
        {
            // TODO: Complete member initialization
            this.eURL = eURL;
        }

        internal static void LoadRequest(SitePage sitePage)
        {
            throw new NotImplementedException();
        }
    }
}

該代碼無法正常工作

好吧,我不確定您打算走哪條路,但是您可以通過以下任一方式打開網頁

  1. 在內部使用WebView

  2. 使用Device.OpenUri

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM