WPF Command Line

前端 未结 4 1725
谎友^
谎友^ 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:10

    You can use the below in app.xaml.cs file :

    private void Application_Startup(object sender, 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();
            //your logic here
        }
    }
    

提交回复
热议问题