var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"images\tile-sdk.png"); if (file != null)
{
// Next, launch the file.
bool success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
...
}
}
添加一个提示功能:
// First, get the image file from the package's image directory.
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileToLaunch);
if (file != null)
{
// Next, configure the warning prompt.
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = true;
// Finally, launch the file.
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
...
} }
出现“ 打开方式”上下文菜单
// First, get the image file from the package's image directory.
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileToLaunch);
if (file != null)
{
// 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 = GetOpenWithPosition(LaunchFileOpenWithButton);
// Next, configure the Open With dialog.
var options = new Windows.System.LauncherOptions();
options.DisplayApplicationPicker = true;
options.UI.InvocationPoint = openWithPosition;
options.UI.PreferredPlacement = Windows.UI.Popups.Placement.Below;
// Finally, launch the file.
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
if (success)
{
...
} }
// The Open With dialog should be displayed just under the element that triggered it.
private Windows.Foundation.Point GetOpenWithPosition(FrameworkElement element)
{
Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null);
Point desiredLocation = buttonTransform.TransformPoint(new Point());
desiredLocation.X = desiredLocation.X + element.ActualWidth/2;
desiredLocation.Y = desiredLocation.Y + element.ActualHeight;
return desiredLocation;
}
打开一个网页:
var uri = new Uri(@"http://www.baidu.com");
// Configure the warning prompt.
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = true;
// Launch the URI.
bool success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
if (success)
{...}}