简体   繁体   English

C#,WPF 集成用户控制

[英]C#,WPF integrated user control

Got a winform in project A (Main project) and which hosts a wpf user control and is maintained under different project called B在项目A (主项目)中有一个 winform,它承载了一个 wpf 用户控件,并在名为B的不同项目下维护

On click of a button on user control,I wanted to query server which is in project " C " and retrieve data and show it on hosted wpf user control.单击用户控件上的按钮时,我想查询项目“ C ”中的服务器并检索数据并将其显示在托管的 wpf 用户控件上。 I know its a bad coding practice to put a reference to s project " C " in project B which includes only custom controls.Any alternative thots would be appreciated...我知道在仅包含自定义控件的项目B中引用 s 项目“ C ”是一种不好的编码习惯。任何替代方案将不胜感激......

To minimize project dependencies, create an interface in your control project (B) that reflects the operations your control requires.为了最大限度地减少项目依赖性,请在您的控制项目 (B) 中创建一个接口,以反映您的控制所需的操作。

Implement a class in your client (A) project that implements this interface (which will obtain the information you need from your data project (C) and pass it back through the interface method).在实现此接口的客户端 (A) 项目中实现 class(它将从数据项目 (C) 中获取您需要的信息并通过接口方法将其传递回)。

Pass the service class (implementing the interface) constructed in A to your control B when you initialize the control.初始化控件时,将A中构造的服务class(实现接口)传递给控件B。

You make another project that is just a class library that can be shared across all three projects.您创建了另一个项目,它只是一个 class 库,可以在所有三个项目之间共享。 You'll put the interfaces and/or the class implementations that need to be shared between the projects in the class library and then just use those in the server and the user-control projects.您将需要在 class 库中的项目之间共享的接口和/或 class 实现,然后在服务器和用户控制项目中使用它们。

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

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