Skip to content

Is there a simple way to pass additional parameters separate from string[] args to shared Application? #17978

Answered by tobyfirth
cirrusone asked this question in Q&A
Discussion options

You must be logged in to vote

One possible way could be to use the overload of AppBuilder.Configure<App>(). The overload takes a Func<TApp> which would allow you to pass the extra args into the constructor of the App.

The code would look something like this

namespace SomeProject.Win;

static class Program
{
    [STAThread]
    public static void Main(string[] args) => BuildAvaloniaApp(new SomeAdditionalClass()).StartWithClassicDesktopLifetime(args);

    public static AppBuilder BuildAvaloniaApp(SomeAdditionalClass args)
        => AppBuilder.Configure<App>(() => new App(args))
            .UsePlatformDetect()
#if DEBUG
        .LogToTrace()
#endif
        .WithInterFont();

}

You could also use the AfterSetup() callb…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cirrusone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants