简体   繁体   中英

WPF Blank Solution with multiple projects sharing same MainWindow

I'm having a Blank solution with multiple projects. I want the Wpfloginwindow to be linked with the other WPF projects (WpfMembers). What I mean is when I click on the connect button in the MainWindow.xaml of the Wpfloginwindow, I want the Mainwindow.xaml of WpfMembers to be shown. How can I do that? I only know how to do that when I'm having multiple windows in one project. But here is different I want to call the WPF window of another project but in the same solution (SlnProject).

在此处输入图像描述

An WPF window is a normal class that inherith from Window class. You can just call your member window from your login window, referencing the namespace from your member window:

Main window Login XAML:

   <Button Click="Button_Click">Connect</Button>

code behind:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var mainWindowMember = new WpfMembers.MainWindow();
        mainWindowMember.Show();
    }

This is the simplest way to implement it. To improve your project architeture and decouple your business logical from UI, maybe you want to implement MVVM pattern:

https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/february/patterns-wpf-apps-with-the-model-view-viewmodel-design-pattern

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