如何使用 Main() 方法从没有 App.xaml 文件的代码启动 UWP 应用程序?
How can I start a UWP application from code without App.xaml file using Main() method?
通常当你创建一个新的通用 Windows 应用程序时,Visual Studio 会生成一个 App.xaml 文件,我假设它会在后台生成应用程序启动方法 Main(string args ).
我需要通过手动编写 Main() 方法在没有 Xaml 文件的情况下启动我的应用程序。
在 WPF 中,我可以编写以下内容:
[STAThread()]
public static void Main() => new MyAppClass().Run();
但是在UWP中Windows.UI.Xaml.Applicationclass中没有运行()方法.所以以上都不行。
我应该编写什么代码来启动应用程序(假设我的应用程序 class 命名为 MyApplication,它继承自 Windows.UI.Xaml.Application)?
找到了!
static void Main(string[] args)
{
Windows.UI.Xaml.Application.Start((p) => new MyApplication());
}
通常当你创建一个新的通用 Windows 应用程序时,Visual Studio 会生成一个 App.xaml 文件,我假设它会在后台生成应用程序启动方法 Main(string args ).
我需要通过手动编写 Main() 方法在没有 Xaml 文件的情况下启动我的应用程序。
在 WPF 中,我可以编写以下内容:
[STAThread()]
public static void Main() => new MyAppClass().Run();
但是在UWP中Windows.UI.Xaml.Applicationclass中没有运行()方法.所以以上都不行。
我应该编写什么代码来启动应用程序(假设我的应用程序 class 命名为 MyApplication,它继承自 Windows.UI.Xaml.Application)?
找到了!
static void Main(string[] args)
{
Windows.UI.Xaml.Application.Start((p) => new MyApplication());
}