xamarin 表单中的超链接按钮

Hyperlink button in xamarin forms

我正在制作一个应用程序,您可以在其中点击一个按钮并打开某个网页。我对应用程序开发很陌生。页面上将有多个具有不同 links 的按钮(从 links 的数据库中获取)。因此,如果可能的话,必须有某种方法来制作一个通用方法,该方法从 xaml 页面接受 link。像这样打开 link 的最佳方式是什么?非常感谢任何帮助

这是微型表格的当前 xaml 代码

<StackLayout Orientation="Horizontal">
 <StackLayout Orientation="Vertical">
  <Label Text="Link 1" TextColor="{StaticResource Text}" FontSize="18" FontAttributes="Bold" x:Name="label"/>
  <StackLayout Orientation="Horizontal">
   <Label Text="+85" TextColor="{StaticResource Text}" FontSize="18"/>
   <Label Text="+/-12" TextColor="{StaticResource Text}" FontSize="18"/>
   </StackLayout>
 </StackLayout>
 <Button Margin="0,10,0,0" Text="Open Link" BackgroundColor="{StaticResource Primary}" TextColor="{StaticResource Accent}" FontSize="13" Clicked="OpenBrowser"/>
</StackLayout>

这是 xaml.cs

中的当前 OpenBrowser 代码
public async Task OpenBrowserAsync()
        {
            await Browser.OpenAsync("https://www.google.com");
        }

private void OpenBrowser(object sender, EventArgs e)
        {
            _ = OpenBrowserAsync();
        }

您可以将 url 嵌入 ClassId 属性

<Button Text="Open Link" Clicked="OpenBrowser" ClassId="http://www.google.com" ... />

然后在你的处理程序中

private async void OpenBrowser(object sender, EventArgs e)
{
   var button = (Button)sender;
   var url = button.ClassId;

   await Browser.OpenAsync(url);
}