2012-08-31 65 views
0

我想在启动地铁应用程序(按城市启动屏幕上的应用程序磁贴)时从地铁应用程序进入win32桌面。一种方法是在启动metro应用程序时打开文件(例如TXT文件)。我将下面的代码逻辑添加到OnLaunched中,有时它可以打开文件并进入桌面,但有时它不会。有人能帮助我吗? (只需在VS2012中创建一个空白的应用程序)。在启动时从地铁应用程序进入win32桌面

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

}

+0

您是否尝试过创建一个WinForms应用程序,该应用程序在启动时立即退出并启动该应用程序? – PhonicUK

回答

0

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

相关问题