title: In UWP App, read command line arguments and pass it from App.xaml.cs file to the MainPage.xaml.cs
body: <p>I can start my <code>UWP</code> app from windows command prompt or PowerShell. I've gotten some idea on how to read the arguments passed to the UWP app, as well. But, I have not been able to find any documentation on how to pass those arguments from <code>App.xaml.cs</code> file to the <code>MainPage.xaml.cs</code>.</p>
  
  <p>For example, you can define an app execution alias - as shown below - for your UWP app, so you can launch it easily from <code>cmd</code> or <code>powershell</code>:</p>
  
  <pre><code>&lt;Extensions&gt;
      &lt;uap5:Extension
        Category="windows.appExecutionAlias"
        StartPage="index.html"&gt;
        &lt;uap5:AppExecutionAlias&gt;
          &lt;uap5:ExecutionAlias Alias="MyApp.exe" /&gt;
        &lt;/uap5:AppExecutionAlias&gt;
      &lt;/uap5:Extension&gt;
  &lt;/Extensions&gt;
  </code></pre>
  
  <p>You can then read arguments from the <code>OnActivated</code> event as shown below:</p>
  
  <pre><code>async protected override void OnActivated(IActivatedEventArgs args)
  {
      switch (args.Kind)
      {
          case ActivationKind.CommandLineLaunch:
              CommandLineActivatedEventArgs cmdLineArgs = 
                  args as CommandLineActivatedEventArgs;
              CommandLineActivationOperation operation = cmdLineArgs.Operation;
              string cmdLineString = operation.Arguments;
              string activationPath = operation.CurrentDirectoryPath;
  ……..
  }
  </code></pre>
  
  <p><strong>Question</strong>: From the above event in <code>App.xaml.cs</code> file, how do I pass the value of the string <code>cmdLineString</code> to <code>MainPage.xaml.cs</code> file? <strong>Example</strong>: I pass <code>Hello World</code> to command line. The <code>App.xaml.cs</code> file reads that argument. Now through my code, I want to pass that <code>Hello World</code> value to <code>MainPage.xaml.cs</code> file so I can assign it to, say, <code>TextBlock.Text</code> property in the main window.</p>
  
  <p><strong>Environment</strong>: <code>VS2019 - ver 16.5.5</code>, <code>Windows 10 Pro - 1903</code></p>