WPF Command Line


I am trying to create a WPF application that takes command line arguments. If no arguments are given, the main window should pop up. In cases of some specific command line arguments, code should be run with no GUI and exit when finished. Any suggestions on how this should properly be done would be appreciated.

Best Solution

First, find this attribute at the top of your App.xaml file and remove it:


That means that the application won't automatically instantiate your main window and show it.

Next, override the OnStartup method in your App class to perform the logic:

protected override void OnStartup(StartupEventArgs e)

    if ( /* test command-line params */ )
        /* do stuff without a GUI */
        new Window1().ShowDialog();