【发布时间】:2021-04-07 18:56:33
【问题描述】:
编辑: 我只是检查整个标签是否为空白,而不是标签中的 URL,因此它导致始终为空白并始终抛出异常。
我希望能够在用户的默认浏览器中通过单击按钮打开特定 URL,例如 YouTube 视频、谷歌搜索等
使用await Windows.System.Launcher.LaunchUriAsync(new Uri(url)); 时,URL 无效,此方法仅打开“普通”网站,例如https://microsoft.com。
有什么方法可以在点击按钮时打开特定的 URL?
代码:
private async void imageTapEvent(object sender, RoutedEventArgs e)
{
try
{
if (((String)(((Image)sender).Tag)) != "")
await Windows.System.Launcher.LaunchUriAsync(new Uri(((ImageTag)(((Image)sender).Tag)).url));
}
catch (Exception)
{
MessageDialog msg = new MessageDialog("The chosen URL is invalid", "Invalid URL");
await msg.ShowAsync();
}
标记是保存为字符串的 URL。
【问题讨论】: