【发布时间】:2020-02-13 10:11:51
【问题描述】:
我有一个在 Core 3.0 上运行的 WPF 应用程序。我通过 Windows 应用程序打包项目发布了它。因为它是 WPF 应用程序,所以我需要将其添加到 appxmanifest:
<Extensions>
<uap5:Extension
Category="windows.appExecutionAlias"
Executable="MyApp.exe"
EntryPoint="MyApp">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
然后我将 WPF 应用程序发布为旁加载,当我从 Windows 开始菜单启动它时它工作得很好。问题是我需要从命令行启动它,并且我需要传递一些命令行参数。但是,当我通过键入别名从命令行启动应用程序时,它只传递这个参数: -服务器名称:App.App7adfdfg54shnsdfh87asrgsdfg1.mca 这不是我的论点——我的论点根本没有通过。因此,我尝试将其添加到我的 WPF .csproj 文件中:
<Reference Include="Windows.Foundation.UniversalApiContract">
<HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
<IsWinMDFile>true</IsWinMDFile>
</Reference>
所以我可以在我的 WPF App.xaml.cs 文件中调用它:
using test = Windows.ApplicationModel.AppInstance;
...
Windows.ApplicationModel.Activation.IActivatedEventArgs args = test.GetActivatedEventArgs();
但是在这样做之后,args 为空。任何想法如何解决这个问题并实际将参数传递给我的 WPF 应用程序?谢谢。
【问题讨论】:
-
您好,您不能通过命令行(甚至 WPF 应用程序)将参数传递给 UWP 应用程序。您可以考虑使用 URI 方案而不是命令行方案,这是 documentation
-
你在哪里打电话
Windows.ApplicationModel.AppInstance.GetActivatedEventArgs()?当它是null时,你是否在容器内运行? -
我在 App.xaml.cs 文件中 OnStartup 方法的开头调用它。
-
@JiříBatulka:你如何确认它是
null? -
@mm8 if (args == null) 语句后的简单消息框。