I have two separate project for example project1 and project2. Well i have a window1 in the project1 so how can i show this window1 from project2.
我有两个单独的项目,例如project1和project2。那么我在project1中有一个window1,那么如何从project2中显示这个window1。
2 个解决方案
#1
9
You just need to add a project reference to the project you want to call the other project from. You can then do something like this. I have 2 different Namespaces but something like this should work.
您只需要向要调用其他项目的项目添加项目引用。然后你可以做这样的事情。我有两个不同的命名空间,但这样的东西应该工作。
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WpfApplication2.MainWindow newForm;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
newForm = new WpfApplication2.MainWindow();
newForm.Show(); // or newForm.ShowDialog();
}
}
}
#2
1
What you need to do is to add Project 1 reference to Project 2 project and then call window1 as you're used to do (Don't forget before calling : you need using Project1;
where you want to call window1 so the intellisense would find it easly for you)
你需要做的是将Project 1引用添加到Project 2项目,然后像你习惯的那样调用window1(在调用之前不要忘记:你需要使用Project1;你想在哪里调用window1以便intellisense找到它它很容易为你)
#1
9
You just need to add a project reference to the project you want to call the other project from. You can then do something like this. I have 2 different Namespaces but something like this should work.
您只需要向要调用其他项目的项目添加项目引用。然后你可以做这样的事情。我有两个不同的命名空间,但这样的东西应该工作。
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WpfApplication2.MainWindow newForm;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
newForm = new WpfApplication2.MainWindow();
newForm.Show(); // or newForm.ShowDialog();
}
}
}
#2
1
What you need to do is to add Project 1 reference to Project 2 project and then call window1 as you're used to do (Don't forget before calling : you need using Project1;
where you want to call window1 so the intellisense would find it easly for you)
你需要做的是将Project 1引用添加到Project 2项目,然后像你习惯的那样调用window1(在调用之前不要忘记:你需要使用Project1;你想在哪里调用window1以便intellisense找到它它很容易为你)