简体   繁体   English

WPF 多个项目共享同一个主窗口的空白解决方案

[英]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).我希望 Wpfloginwindow 与其他 WPF 项目(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.我的意思是当我单击 Wpfloginwindow 的 MainWindow.xaml 中的连接按钮时,我希望显示 WpfMembers 的 Mainwindow.xaml。 How can I do that?我怎样才能做到这一点? I only know how to do that when I'm having multiple windows in one project.我只有在一个项目中有多个 windows 时才知道该怎么做。 But here is different I want to call the WPF window of another project but in the same solution (SlnProject).但这里不同,我想调用另一个项目的 WPF window 但在同一个解决方案(SlnProject)中。

在此处输入图像描述

An WPF window is a normal class that inherith from Window class. 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:您可以从您的登录 window 中调用您的成员 window,从您的成员 window 引用命名空间:

Main window Login XAML:主window登录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:为了改进您的项目架构并将您的业务逻辑与 UI 分离,您可能想要实现 MVVM 模式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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