我想在启动 Metro 应用程序时从 Metro 应用程序进入 win32 桌面(在 Metro 启动屏幕上按应用程序的磁贴)。一种方法是在启动 Metro 应用程序时打开一个文件(例如 TXT 文件)。我在 OnLaunched 中添加了以下代码逻辑,有时它可以打开文件并进入桌面,但有时它不能。有人可以帮助我吗?(只需在 VS2012 中创建一个空白应用程序)。
async protected override void OnLaunched(LaunchActivatedEventArgs args) {
// Do not repeat app initialization when already running, just ensure that the window //is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
Window.Current.Activate();
return;
}
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Create a Frame to act navigation context and navigate to the first page
// var rootFrame = new Frame();
if (!rootFrame.Navigate(typeof(MainPage)))
{
throw new Exception("Failed to create initial page");
}
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
{
string txtfile = @"Assets\a.txt";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(txtfile);
if (file != null)
{
bool success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
}
else
{
}
}
}
}