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

文章目录

    例如,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 本地的其他程序。

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式