WPF Command Line

前端 未结 4 1774
谎友^
谎友^ 2020-11-27 12:32

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 a

4条回答
  •  感动是毒
    2020-11-27 13:18

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

    StartupUri="Window1.xaml"
    

    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)
    {
        base.OnStartup(e);
    
        if ( /* test command-line params */ )
        {
            /* do stuff without a GUI */
        }
        else
        {
            new Window1().ShowDialog();
        }
        this.Shutdown();
    }
    

提交回复
热议问题