/// <summary> // Launch a URI. Show an Open With dialog that lets the user chose the handler to use. /// </summary> private async void LaunchUriOpenWith(object sender, RoutedEventArgs e) { // Create the URI to launch from a string. var uri = new Uri(UriToLaunch.Text); // Calulcate the position for the Open With dialog. // An alternative to using the point is to set the rect of the UI element that triggered the launch. Point openWithPosition = MainPage.GetElementLocation(sender); // Next, configure the Open With dialog. var options = new LauncherOptions(); options.DisplayApplicationPicker = true; options.UI.InvocationPoint = openWithPosition; options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below; // Launch the URI. bool success = await Launcher.LaunchUriAsync(uri, options); if (success) { rootPage.NotifyUser("URI launched: " + uri.AbsoluteUri, NotifyType.StatusMessage); } else { rootPage.NotifyUser("URI launch failed.", NotifyType.ErrorMessage); } }
/// <summary> // Launch a .png file that came with the package. Show an Open With dialog that lets the user chose the handler to use. /// </summary> private async void LaunchFileOpenWith(object sender, RoutedEventArgs e) { // First, get the image file from the package's image directory. var file = await GetFileToLaunch(); // Calculate the position for the Open With dialog. // An alternative to using the point is to set the rect of the UI element that triggered the launch. Point openWithPosition = MainPage.GetElementLocation(sender); // Next, configure the Open With dialog. var options = new LauncherOptions(); options.DisplayApplicationPicker = true; options.UI.InvocationPoint = openWithPosition; options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below; // Finally, launch the file. bool success = await Launcher.LaunchFileAsync(file, options); if (success) { rootPage.NotifyUser("File launched: " + file.Name, NotifyType.StatusMessage); } else { rootPage.NotifyUser("File launch failed.", NotifyType.ErrorMessage); } }