nishihara.me


navigation
home
twitter
github
flickr
about
I am a developer and photography enthusiast.

Getting console arguments on WPF

06 May 2015

To get console arguments on applications developed with WPF framework it is needed some small modifications on App.xaml and App.xaml.cs files.

First, remove the following from the App.xaml:

StartupUri="MainWindow.xaml"

Then, use the following snippet on App.xaml.cs:

protected override void OnStartup(StartupEventArgs e)
{
	MainWindow WindowToDisplay = new MainWindow();

	if (e.Args.Length == 0)
	{
		WindowToDisplay.Show();
	}	
	else
	{
		string firstArgument = e.Args[0].ToString();
		string secondArgument = e.Args[1].ToString();
		// third ...
	}
}

Resource: