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.
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.
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();
}
精彩评论