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

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

问题描述

我是一个相对缺乏经验的专业程序员(我只有20岁).因此,我谨此致歉,因为可能还有一些我尚未完全掌握的较大概念.我希望这是一个适当的问题,因为一个小时的谷歌搜索无法帮助我.

I am a relatively inexperienced professional programmer (I'm only 20 years old). Therefore, I apologize in advance as there may be some larger concepts that I do not fully grasp yet. I hope this is an appropriate question to ask, as an hour of googling could not help me.

我基本上想使用标签类在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.

推荐答案

您不能真正做到这一点,因为默认情况下,Labels不响应用户输入,但是您可以通过手势实现类似的操作

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天全站免登陆