C # UWP Open Web Address with Microsoft Edge

I want to open a URL using Microsoft Edge in my UWP. Search, I found this code:

using System.Diagnostics; 
using System.ComponentModel; 

private void button_Help_Click(object sender, RoutedEventArgs e)
{
    Process.Start("microsoft-edge:http://www.bing.com");
}

But it shows the following error:

The process name does not exist in the current context.

If I press Ctrl+ ., it only displays class parameters.

Any help is appreciated.

+4
source share
2 answers

Process.Start is a traditional method used in the .NET Framework that cannot be used directly in UWP applications. To open a Web URI with Microsoft Edge in UWP, we can use the Launcher.LaunchUriAsync method . For instance:

// 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
   }
}

URI - . Microsoft Edge, Launcher.LaunchUriAsync(Uri, LauncherOptions) LauncherOptions.TargetApplicationPackageFamilyName. 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
   }
}
+15

, Microsoft Edge . .

private async void launchURI_Click(object sender, RoutedEventArgs e)      
{       
     // The URI to launch
     var uriBing = new Uri(@"http://www.bing.com");

     // Launch the URI
     var success = await Launcher.LaunchUriAsync(uriBing);             
}
+2

All Articles