Process.Start是.NET Framework中使用的传统方法,不能直接在UWP应用程序中使用.要在UWP中使用Microsoft Edge打开Web URI,我们可以使用
Launcher.LaunchUriAsync method.例如:
// The URI to launch
string uriToLaunch = @"http://www.bing.com";
// Create a Uri object from a URI string
var uri = new Uri(uriToLaunch);
// Launch the URI
async void DefaultLaunch()
{
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
但是,这将使用默认Web浏览器打开URI.要始终使用Microsoft Edge打开它,我们可以将Launcher.LaunchUriAsync(Uri, LauncherOptions) method与指定的LauncherOptions.TargetApplicationPackageFamilyName property一起使用.TargetApplicationPackageFamilyName属性可以指定应该用于启动文件或URI的目标包.对于Microsoft Edge,其软件包系列名称为“Microsoft.MicrosoftEdge_8wekyb3d8bbwe”.以下是一个示例,说明如何使用它.
// The URI to launch
string uriToLaunch = @"http://www.bing.com";
var uri = new Uri(uriToLaunch);
async void LaunchWithEdge()
{
// Set the option to specify the target package
var options = new Windows.System.LauncherOptions();
options.TargetApplicationPackageFamilyName = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe";
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}