【问题标题】:Launch UWP app from Windows Form - entry point?从 Windows 窗体启动 UWP 应用程序 - 入口点?
【发布时间】:2017-03-23 15:06:45
【问题描述】:

我的 VS2013 解决方案中有两个项目:

  1. 一个从本地 json 文件消费/生成数据的 UWP 应用程序

    • 这会被侧载并且很有效
  2. 从远程服务器获取数据的 Windows 窗体 使用网络服务

我希望表单上有一个按钮,以便在获取数据后启动 UWP 应用。 (我无法将两者集成,因为 Web 服务身份验证库不适用于 W8.1)

但是,此方法仅启动我的 UWP 初始屏幕。它不会进入代码。

 Process.Start("MyUWPApp:");

我需要这样的东西吗:

 Process.Start("MyUWPApp:MyEntryPoint");

MyEntryPoint 将在 UWP 上的清单文件中去哪里?我一直在尝试文件中 MyentryPoint 的各种值,例如: App、MainPage.cs、Main() 等。我不确定这是否是要走的路……有人吗?

【问题讨论】:

    标签: c# uwp windows-8.1 windows-10-universal


    【解决方案1】:

    您必须覆盖 App.xaml.cs 中的 OnActivated(IActivatedEventArgs args) 方法才能处理 UWP 应用中的协议激活。看看 MSDN 上的here,那里有解释。

    我已经以这种方式实现了它,它在我的应用程序中完美运行:

    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);
    }
    

    【讨论】:

      【解决方案2】:

      以下代码对我有帮助。将代码添加到 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();
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-01
        • 2020-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-09
        相关资源
        最近更新 更多