从 Windows 表单启动 UWP 应用 - 入口点?
Launch UWP app from Windows Form - entry point?
我的 VS2013 解决方案中有两个项目:
一个 UWP 应用,consumes/produces 数据 from/to 本地 json 文件
- 这会被旁路加载并起到很好的作用
A Windows 从远程服务器获取数据的表单
与网络服务
我希望我的表单上有一个按钮,用于在获取数据后启动 UWP 应用程序。
(我无法将两者集成,因为 Web 服务身份验证库不能与 W8.1 一起使用)
然而,此方法仅启动我的 UWP 初始屏幕。它不会进入代码。
Process.Start("MyUWPApp:");
我需要这样的东西吗:
Process.Start("MyUWPApp:MyEntryPoint");
MyEntryPoint 将在 UWP 的清单文件中放在哪里?我一直在尝试文件中 MyentryPoint 的各种值,例如:
应用程序、MainPage.cs、Main() 等。我不确定这是不是要走的路。有人吗?
您必须覆盖 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);
}
以下代码有助于 me.Add 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();
}
}
我的 VS2013 解决方案中有两个项目:
一个 UWP 应用,consumes/produces 数据 from/to 本地 json 文件
- 这会被旁路加载并起到很好的作用
A Windows 从远程服务器获取数据的表单 与网络服务
我希望我的表单上有一个按钮,用于在获取数据后启动 UWP 应用程序。 (我无法将两者集成,因为 Web 服务身份验证库不能与 W8.1 一起使用)
然而,此方法仅启动我的 UWP 初始屏幕。它不会进入代码。
Process.Start("MyUWPApp:");
我需要这样的东西吗:
Process.Start("MyUWPApp:MyEntryPoint");
MyEntryPoint 将在 UWP 的清单文件中放在哪里?我一直在尝试文件中 MyentryPoint 的各种值,例如: 应用程序、MainPage.cs、Main() 等。我不确定这是不是要走的路。有人吗?
您必须覆盖 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);
}
以下代码有助于 me.Add 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();
}
}