0
votes

I am trying to write an aspx page containing a button whose click event should result in opening of a WPF form for further processing. I am trying to use a new process object to launch the WPF application.

I am using the following code in the code behind:

protected void Btn_Click(object sender, EventArgs e)
        {
            Process WPF = new Process();
            WPF.StartInfo.FileName = "WpfApplication1.exe";
            WPF.Start();
        }

On execution, the button click executes without any exception, but the WPF window is not opened.

Can someone please help me.

Thanks.

2
I googled a bit and found the following discussion: social.msdn.microsoft.com/forums/en-US/wpf/thread/… The summary is WPF cannot be launched from ASP.NET. For that XBAP is required.Jake
your comment is the answer (it's exactly what i would have said in my answer).slugster
Please do not post that as a comment, post it as an answer and accept it.H.B.

2 Answers

2
votes

The code you posted starts (or attempts to start) the WPF application on the server

If you want the client to run a WPF application you could use an XBAP application or a regular WPF application that is distributed through ClickOnce deployment so you can add a link to the application on your web page.

0
votes

To launch WPF form from asp.net go to the View Code of code behind and Create an object for the WPF form and in the Page_Load event paste the following code

 protected void Page_Load(object sender, EventArgs e)
        {
            Thread t = new Thread(() =>
            {
                mainWindow = new MainWindow();
                mainWindow.Show();
                System.Windows.Threading.Dispatcher.Run();
            });
            t.SetApartmentState(ApartmentState.STA);
            t.IsBackground = true;
            t.Start();
            createDB();
        }