Prash
Prash

Reputation: 124

Run WPF application with custom command parameters from command prompt

I want to run wpf application with custom parameters in command prompt, basically this is achieve with no gui, if i don't run from command prompt, it should show gui!

Upvotes: 2

Views: 1319

Answers (1)

sanguine
sanguine

Reputation: 291

Do this-

1) Add event -> Startup="App_Startup" to App.Xaml

2) Add Event handler for "App_Startup" to App.Xaml.cs

3) In "App_Startup" you can check command params this way-

     if (e.Args.Length == 0)
        {
            MainWindow m = new MainWindow();
            m.Show();
        }

4) Remove StartupUri from App.Xaml

This way WPF GUI will appear only if there is no command args.

Upvotes: 3

Related Questions