Passing arguments to main method of wpf application

Pablo gil 86 Reputation points
2022-09-01T20:36:24.967+00:00

I want to set a read-only property of the App class, so you have to do it in its ctor., as far a I know, when you call Process.Start(startInfo) to pass startInfo.AgumentList, you have these arguments available in the Application Startup event or when you override OnStartup, but I need them in Main(string[] args) like shown below, please can anybody help me?.

    public partial class App : Application  
    {  
        public string Name { get; }  

        [STAThread] static void Main(string[] args)  
        {  
            var myApp = new App(args[0]);  
            myApp.Run()  
        }  

        public App(string name)  
        {  
            Name = name;  
        }  

        protected override void OnStartup(StartupEventArgs e)  
        {  
            base.OnStartup(e);  
            Window window = new MainWindow();  
            window.Show();      
        }      
    }  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pablo gil 86 Reputation points
    2022-09-02T04:10:01.143+00:00

    Main(string[] args) also gets startInfo.AgumentList when calling Process.Start(startInfo)

    0 comments No comments