如何使用Xamarin.Forms中的外部浏览器创建可点击标签以打开外部URL?

Dpe*_*nha 10 xamarin xamarin.forms

Xamarin中没有类似LinkBut​​ton的东西吗?

我想创建一个带有url链接外观的标签,一旦点击就会打开外部浏览器.

我还需要知道如何在便携式项目中打开设备的外部浏览器(打开指定的URL).

谢谢

Sus*_*ver 9

Xamarin.Forms在默认移动浏览器中打开URL字符串的方法:

Device.OpenUri(new Uri("http://example.com"))
Run Code Online (Sandbox Code Playgroud)

虽然表单' Label没有点击事件,但您可以添加一个表单,TapGestureRecognizer点击标签时它会执行Device.OpenUri.

例:

var myURLLabel = new Label
{
    Text = "https://xamarin.com"
};

myURLLabel.GestureRecognizers.Add(new TapGestureRecognizer
{
    Command = new Command(() => {
        Device.OpenUri(new Uri(myURLLabel.Text));
    })
});
Run Code Online (Sandbox Code Playgroud)

Xamarin-Forms-Labs' ExtendedLabel允许您将标签的文本设置为带下划线的....

参考:https://github.com/XLabs/Xamarin-Forms-Labs/wiki/ExtendedLabel

  • 谢谢.很遗憾我需要一个外部库.Xamarin看起来非常令人失望. (2认同)