WPF用户控件中的WinForms

WPF用户控件中的WinForms

本文介绍了WPF用户控件中的WinForms:项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景

我决定上班WPF技术为我的新的应用程序。此应用程序被称为单击菜单从一个WinForms窗口。所以,我创建了一个WPF用户控件库并将其整合利用元素主机在父母的WinForms形式显示。

I decided to work on WPF technology for my new application. This application has to be called on Menu click from a WinForms window. So I created a WPF UserControl Library and integrate it to display in parent WinForms Form using Element Host.

我的应用程序

它包含在里面另一个用户控件与tabContent控制封装3子用户控件。我prefered这种方法烧制的儿童用户控件的事件和处理的WinForms(订阅事件)似乎是痛苦的。

It contains 3 child usercontrols which are encapsulated inside another usercontrol with tabContent Control. I prefered this approach as firing events from Child UserControl and handling in WinForms (subscribing events) seemed painful.

我的提问

现在面临的访问里面,我创建了数据管理类进行适当的项目结构原因的WinForms用户控件元素相同的痛苦的任务(用户控件不应该包含数据管理类UI)。请指导我一下,如何构建我的项目/如何订阅里面WPF事件/访问WPFUserControl元素。

Now facing the same painful task of accessing UserControl elements inside Winforms where I have created Data Manager class for proper project structuring reasons (UserControl should not contain Data Manager class-UI). Please guide me as to how to structure my project/how to subscribe events/access WPFUserControl elements inside WPF.

推荐答案

看看信使类 MVVM光工具包的(也可以独立使用)。它可以帮助你解耦控制。信使作品发布/订阅模式。您的WPF用户控件可以发布对象,在的WinForms主机可以在这些通知听。所交换的消息(对象)最好放置在单独的程序,因为它们定义UC WPF库和WinForms应用程序之间共享的合同。

Take a look at the Messenger class of MVVM Light Toolkit (can also be used standalone). It helps decoupling your controls. The messenger works with a publish/subscribe pattern. Your WPF UserControls can publish objects, the WinForms Host can listen on those notifications. The exchanged messages (objects) are best placed in separate assembly, as they define the shared contract between WPF UC-library and WinForms application.

这篇关于WPF用户控件中的WinForms:项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:20