如何在 xamarin.forms 应用程序中添加 url

D V*_*D V 5 xaml xamarin.forms

您好,我想构建一个简单的 xamarin.forms 应用程序,所以我在这里有 xaml 代码,所以在这段代码中我想添加网站 url,所以有人可以帮助我需要在 xaml 代码中添加哪些选项来添加网站 url 吗?当我尝试使用标签和文本选项添加 url 时,我想在标签杂货下方添加链接,该 url 仍然像标签一样,但我希望以这样的方式,如果我单击 url,它应该将我带到浏览器中的网站。

 <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="MyApp.AboutPage">
   <ContentPage.Content>
    <StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand" 
 VerticalOptions="CenterAndExpand">
        <Label Text="My List" />
        <Label Text="groceries"/>
        <Button BackgroundColor="black" TextColor="White" WidthRequest="40" 
  HeightRequest="40" Text="OK" Clicked="OnRedirectMain" 
   BorderColor="Transparent" BorderWidth="1"/>

    </StackLayout>
</ContentPage.Content>
 </ContentPage>
Run Code Online (Sandbox Code Playgroud)

Jas*_*son 5

<Button Text="Google" Clicked="GoGoogle" />

protected void GoGoogle(object sender, EventArgs e) {
  Device.OpenUri(new Uri("http://www.google.com"));
}
Run Code Online (Sandbox Code Playgroud)

如果你不想使用 Button,你可以使用带有手势的 Label

<Label Text="Google">
  <Label.GestureRecognizers>
      <TapGestureRecognizer Tapped="GoGoogle" />
  </Label.GestureRecognizers>
</Label>

protected void GoGoogle(object sender, EventArgs e) {
      Device.OpenUri(new Uri("http://www.google.com"));
    }
Run Code Online (Sandbox Code Playgroud)