UWP C# 调用默认浏览器打开一个指定网页

发布时间: 2018-12-01 10:37:47 作者: 大象笔记

例如,Windows 10 上点击一个 UWP 桌面程序的按钮,使用默认浏览器 (Chrome)打开我的博客 https://www.sunzhongwei.com

private async void Button_ClickAsync(object sender, RoutedEventArgs e)
{
	var uriBlog = new Uri(@"https://www.sunzhongwei.com");

	// Launch the URI
	var success = await Windows.System.Launcher.LaunchUriAsync(uriBlog);

	if (success)
	{
		// URI launched
		Debug.WriteLine("success");
	}
	else
	{
		// URI launch failed
		Debug.WriteLine("fail");
	}
}

参考

https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app

实际上也可以用同样的方式调起 Windows 本地的其他程序。

我是一名山东烟台的开发者,联系作者