wpf 从另一个项目的可执行文件启动一个项目的可执行文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31573630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Launch one project's executable from another project's executable
提问by blueshift
I have a solution with 6 projects -- four are WPF apps and two are shared model and data access libraries. Normally the WPF apps are run independently. However, I want to add a button to one WPF app that launches one of the other WPF apps.
我有一个包含 6 个项目的解决方案——四个是 WPF 应用程序,两个是共享模型和数据访问库。通常 WPF 应用程序是独立运行的。但是,我想向一个启动其他 WPF 应用程序之一的 WPF 应用程序添加一个按钮。
What code would I need to add to my first WPF app's view model to launch the executable of the second app?
我需要将哪些代码添加到我的第一个 WPF 应用程序的视图模型中以启动第二个应用程序的可执行文件?
采纳答案by Daneau
You either add reference to the assembly of the project you want to start. This way you can simply create an instance and do .show()
您可以添加对要启动的项目程序集的引用。这样你就可以简单地创建一个实例并执行 .show()
The other way would be with Process.Start() and put the path of your executable to run it
另一种方法是使用 Process.Start() 并放置可执行文件的路径来运行它
EDIT:On the project that wish to open other project: right click References-> Add references -> Solution -> check the project you want to create -> OK
编辑:在希望打开其他项目的项目上:右键单击引用-> 添加引用-> 解决方案-> 选中要创建的项目-> 确定
You might need to add extra references if the compiler ask you to (PresentationFramework, system.xaml ...)
如果编译器要求您添加额外的引用(PresentationFramework、system.xaml ...)
And then
进而
private void Button_Click(object sender, RoutedEventArgs e)
{
WpfApplication1.MainWindow mw = new WpfApplication1.MainWindow();
mw.Show();
}
Just change WpfApplication1 to the project's assembly name and MainWindow by the name of the windows you want to call on that assembly
只需将 WpfApplication1 更改为项目的程序集名称,并将 MainWindow 更改为要在该程序集上调用的窗口的名称
回答by sparta93
You can use Process.Start("path/to/your/file")and put the path to the .exeof your other project in it.
您可以使用Process.Start("path/to/your/file")并将.exe其他项目的路径放入其中。

