使用 Xamarin.Forms(xaml 和 c#)创建超链接 [英] Create a hyperlink using Xamarin.Forms (xaml and c#)

查看:27
本文介绍了使用 Xamarin.Forms(xaml 和 c#)创建超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想使用标签类在 Xamarin.Forms 中创建一个超链接.基本上,我想通过以下链接将用户带到 google.com 在网络浏览器中:

I basically want to create a hyperlink in Xamarin.Forms using the label class. Basically, I want to following link to take the user to google.com in a web browser:

<Label Text="http://www.google.com/" />

我在 Xamarin Forms API 中找不到任何关于此的信息,并且互联网在 Xamarin.Forms 中关于此主题的信息模糊且有限.

I can't find anything in the Xamarin Forms API about this and the internet has vague and limited information on this topic in Xamarin.Forms.

这可能吗?如果是这样,有人可以指出我正确的方向吗?在此先感谢回答问题的人.

Is this possible? If so, could someone please point me in the right direction? Thanks in advance to anyone who answers.

推荐答案

你真的不能这样做,因为默认情况下标签不响应用户输入,但你可以通过手势实现类似的东西

You can't really do this because Labels by default don't respond to user input, but you can achieve something similar with gestures

using Xamarin.Forms;
using Xamarin.Essentials;

Label label = new Label();
label.Text = "http://www.google.com/";

var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += async (s, e) => {
    // Depreciated - Device.OpenUri( new Uri((Label)s).Text); 
    await Launcher.OpenAsync(new Uri(((Label)s).Text));
};
label.GestureRecognizers.Add(tapGestureRecognizer);

这篇关于使用 Xamarin.Forms(xaml 和 c#)创建超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆