C#、WPF集成用户控件
在项目 A (主项目)中有一个 winform,它托管一个 wpf 用户控件,并在名为 B 的不同项目下维护
单击用户控件上的按钮,我想要查询项目“C”中的服务器并检索数据并将其显示在托管的 wpf 用户控件上。我知道在项目 B 中引用 s 项目“C”是一种糟糕的编码实践,其中仅包含自定义控件。任何替代方法将不胜感激......
Got a winform in project A (Main project) and which hosts a wpf user control and is maintained under different project called 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. 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了最大限度地减少项目依赖性,请在控制项目 (B) 中创建一个反映控件所需操作的接口。
在您的客户端 (A) 项目中实现一个实现此接口的类(它将从您的数据项目 (C) 获取您需要的信息,并通过接口方法将其传回)。
初始化控件时,将 A 中构造的服务类(实现接口)传递给控件 B。
To minimize project dependencies, create an interface in your control project (B) that reflects the operations your control requires.
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).
Pass the service class (implementing the interface) constructed in A to your control B when you initialize the control.
您创建另一个项目,它只是一个可以在所有三个项目之间共享的类库。您将把需要在类库中的项目之间共享的接口和/或类实现放入类库中,然后仅在服务器和用户控制项目中使用它们。
You make another project that is just a class library that can be shared across all three projects. 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.