[英]How to Open a web page with the click of a button in xamarin form
i have a file in xamarin form called HomePage that take the eURL content from the user. 我有一个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)));
}
}
}
}
and opens eURL from the click of the button bButton and loads the website into into another page called SitePage 并通过单击按钮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();
}
}
}
the code doesn't work, any way out 该代码无法正常工作
Well I am not sure which way you intend to go but you can open a webpage by either 好吧,我不确定您打算走哪条路,但是您可以通过以下任一方式打开网页
Internally using a WebView 在内部使用WebView
Using Device.OpenUri 使用Device.OpenUri
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.