问题
SCENARIO
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.
My Application
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.
My Question
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.
回答1:
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.
来源:https://stackoverflow.com/questions/14706179/wpf-user-control-in-winforms-project-structuring