简体   繁体   中英

Open wpf window from other project

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.

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();
        }
    }
}

你需要做的是将Project 1引用添加到Project 2项目中,然后像你习惯的那样调用window1(在调用之前不要忘记:你需要using Project1;你想在哪里调用window1以便intellisense找到它它很容易为你)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM