Share via

Maui - launch WPF using process info passing parameter to WPF is possible

Dani_S 5,581 Reputation points
2023-08-14T08:31:41.5733333+00:00

Hi,

I want from MAUI launch WPF using process info class passing parameter to WPF is , is it possible?

Can you give an sniped code?

Thanks,

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
2023-08-15T02:45:02.95+00:00

Hello,

After testing, this can be implemented in MAUI, you can refer to the steps below.

In WPF part:

Step 1.Add the Startup event to the App.xaml of your WPF program to receive parameters.

//in xaml
<Application 
    ...
    Startup="Application_Startup">

// in code-behind
private void Application_Startup(object sender, StartupEventArgs e)
{
    foreach (var item in e.Args)
    {
        //Operate on incoming parameters
    }
}

Step 2. Implement the ability to start WPF programs via ProcessStartInfo in MAUI.

private void StartWPFApp(object sender, EventArgs e)
{
    var path = "C:\\wpf1_test\\WpfApp1.exe"; //WPF program path
    if (File.Exists(path))
    {
        ProcessStartInfo startInfo = new ProcessStartInfo(path, "hello world")
        {
            CreateNoWindow = true,
            UseShellExecute = true,
        };
        Process.Start(startInfo);
    }
}

Best Regards,

Alec Liu.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.