c# - 使用 Xamarin.Forms(xaml 和 c#)创建超链接

标签 c# xaml xamarin xamarin.ios xamarin.forms

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

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

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

这可能吗?如果是这样,有人可以指出我正确的方向吗?预先感谢任何回答的人。

最佳答案

你不能真正做到这一点,因为默认情况下标签不会响应用户输入,但你可以通过手势实现类似的效果

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);

关于c# - 使用 Xamarin.Forms(xaml 和 c#)创建超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37597931/

相关文章:

c# - 如何使用 C# for WP8 在网格中显示图像?

listview - Xamarin Forms - 如何从 ListView SelectedItem 获取索引号

ios - 在 iOS Designer 中创建的代码中的访问约束

c# - 了解 cmp(比较器函数)如何用作另一个函数的参数

c# - 如何返回更具体的 HTTP 代码(如 401.X)

javascript - 使用ajax以mvc模式通过 Controller 发送数据

c# - UWP 中的弱事件模式

c# - 基本 WPF 验证和数据绑定(bind)

java - 连接到布局渲染器失败。这可能是Java配置错误导致的

c# - Azure AD 身份验证成功后按公司名称属性过滤掉