Monday, October 5, 2009

WPF Command line arguments.


App.xaml
<Application ...
Startup="App_Startup">
...


App.xaml.cs;
...
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
// Storing your arguments in your type you wish:
public static string Input = "";

void App_Startup(object sender, StartupEventArgs e)
{
// Store the arguments to static public you declared:
Input = String.Join(" ", e.Args);
}
}
...


Window1.xaml.cs
...
/// <summary>
/// Create window.
/// </summary>
public Window1()
{
Console.WriteLine(App.Input); // Woohoo! Got the input...
...

See, MSDN, you don't have to be so damn verbose always, when little codespeak would do.

No comments: