I have a WPF C# application, to which I have to pass command line argument. The argument is actually a URL, which I have to then use in my application?
我有一个WPF c#应用程序,我必须将命令行参数传递给它。这个参数实际上是一个URL,我必须在我的应用程序中使用它吗?
How are these command line arguments passed in WPF C#, so that the application can pickup the url during launch?
如何在WPF c#中传递这些命令行参数,以便应用程序能够在启动时获取url ?
3 个解决方案
#1
55
In your App.xaml.cs
在你App.xaml.cs
class App : Application
{
//Add this method override
protected override void OnStartup(StartupEventArgs e)
{
//e.Args is the string[] of command line argruments
}
}
#2
27
It has been mentioned by linquize above, but I think it is worth an answer of its own, as it is so simple...
上面的linquize提到过,但是我认为它值得一个自己的答案,因为它是如此的简单……
You can just use:
你可以使用:
string[] args = Environment.GetCommandLineArgs();
That works anywhere in the application, not just in App.xaml.cs
它可以在应用程序的任何地方工作,而不仅仅是在app .xam .cs中
#3
0
You can pass arguments like "no-wpf" C# applications through comman line. The difference is the application entry point. In WPF is App.xaml.cs. So, you have in this file you can pick arguments in this way:
您可以通过逗号行传递诸如“no-wpf”c#应用程序之类的参数。区别在于应用程序入口点。在WPF App.xaml.cs。在这个文件中你可以这样选择参数
class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
//e.Args represent string[] of no-wpf C# applications
}
}
#1
55
In your App.xaml.cs
在你App.xaml.cs
class App : Application
{
//Add this method override
protected override void OnStartup(StartupEventArgs e)
{
//e.Args is the string[] of command line argruments
}
}
#2
27
It has been mentioned by linquize above, but I think it is worth an answer of its own, as it is so simple...
上面的linquize提到过,但是我认为它值得一个自己的答案,因为它是如此的简单……
You can just use:
你可以使用:
string[] args = Environment.GetCommandLineArgs();
That works anywhere in the application, not just in App.xaml.cs
它可以在应用程序的任何地方工作,而不仅仅是在app .xam .cs中
#3
0
You can pass arguments like "no-wpf" C# applications through comman line. The difference is the application entry point. In WPF is App.xaml.cs. So, you have in this file you can pick arguments in this way:
您可以通过逗号行传递诸如“no-wpf”c#应用程序之类的参数。区别在于应用程序入口点。在WPF App.xaml.cs。在这个文件中你可以这样选择参数
class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
//e.Args represent string[] of no-wpf C# applications
}
}