简体   繁体   中英

Opening a new Window from a separate project in C# WPF

I am currently developing a C# WPF project. The solution has two projects, one called GUI which contains all the Windows and GUI controls of the program and a second project called coding which contains all the classes and logic to ensure that if I change the logic, it doesn't affect the working of the GUI.

In the GUI project I have added a reference to the coding project and said using Coding, and this allows me to access the logic classes from the GUI screens.

However, if in the Coding logic class project I want to load a new window from the GUI project how do I go about doing this. If I try and add a reference to the GUI project from the coding project it says that this can't be done as it creates a circular dependency.

How can I reference both the projects together so that GUI can access logic classes from the coding project and reference the gui project from the coding project so the coding logic class can open a new window from the gui project.

Thanks for any help you can provide.

You can decouple it by introducing the third project Common and move out Window and other shared classes into it. Then Gui and Coding projects can easily reference Common .

BTW, try to rethink your design because I'm worried that Coding project is aware of UI entities.

EDIT:

In WPF you can decouple UI stuff from a logic by using Commands , see whether yu can achieve this.

当我们谈论WPF和SOC“问题的分离”时,这直接将我们引向MVVM, 这里简单解释

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