在启动时从metro app进入win32桌面

时间:2012-08-31 08:27:41

标签: c# microsoft-metro desktop launcher

我想在启动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
         {
         }
    }
}

}

1 个答案:

答案 0 :(得分:0)

BatRT允许您从metro应用程序执行批处理文件。这可用于从metro应用程序运行任何桌面应用程序。一旦metro应用程序开始执行批处理文件以运行所需的桌面应用程序。