从Windows窗体启动UWP应用程序 - 入口点是什么?

3
我在我的VS2013解决方案中有两个项目:
  1. 一个UWP应用程序,从/向本地json文件消费/生成数据

    • 这个应用程序是通过侧载实现的,运行良好
  2. 一个Windows窗体应用程序,通过Web服务从远程服务器获取数据

我想在我的窗体上添加一个按钮,在数据被获取后启动UWP应用程序。 (由于身份验证库不支持W8.1,因此无法将两者集成)

然而,这种方法只能启动我的UWP启动画面,而不能进入代码。

 Process.Start("MyUWPApp:");

我需要类似这样的东西吗?
 Process.Start("MyUWPApp:MyEntryPoint");

MyEntryPoint应该放在UWP清单文件的哪个位置?我已经试过很多不同的值,例如App、MainPage.cs、Main()等等。但我不确定这是否正确,请问有人知道吗?

2个回答

3
你需要在你的App.xaml.cs中重写OnActivated(IActivatedEventArgs args)方法来处理你的UWP应用程序中的协议激活。请参考MSDN上的说明
我已经按照这种方式实现了它,在我的应用程序中完美运行。
private async void Initialize(IActivatedEventArgs args)
{
    // My code copied from original OnLaunched method with some minor changes
}

protected override void OnActivated(IActivatedEventArgs args)
{
    Initialize(args);
}

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Initialize(e);
}

1
以下代码对我很有帮助。将代码添加到App.Xaml.cs文件中。
protected override void OnActivated(IActivatedEventArgs args)
    {
        Initialize(args);
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            // Always navigate for a protocol launch
            rootFrame.Navigate(typeof(MainPage), eventArgs.Uri.AbsoluteUri);
            // Ensure the current window is active
            Window.Current.Activate();
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接