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