我有一个使用WPF C#编写的应用程序,需要传递命令行参数。这个参数实际上是一个URL,在我的应用程序中我需要使用它。
在WPF C#中如何传递这些命令行参数,以便应用程序可以在启动时获取URL?
class App : Application
{
//Add this method override
protected override void OnStartup(StartupEventArgs e)
{
//e.Args is the string[] of command line arguments
}
}
MainWindow.xaml
等文件中,对吗? - Cipher如linquize所提到的,但我认为这值得单独回答,因为它非常简单...
你只需使用:
string[] args = Environment.GetCommandLineArgs();
这在整个应用程序中都有效,不仅仅适用于App.xaml.cs文件。
class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
//e.Args represent string[] of no-wpf C# applications
}
}