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
{
}
}
}
}
您是否嘗試過創建一個WinForms應用程序,該應用程序在啓動時立即退出並啓動該應用程序? – PhonicUK