我基本上想使用标签类在 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)