1

My project is written in WinForms (C#). I have WPF user control (implemented as MVVM) that would be placed in the project. Some WinForms user controls should talk/react on changes made in WPF user control. I can think of couple approaches:

  1. user controls can expose properties. For example: UC3 will have reference to UC4 which will have reference to WPF-UC. UC3 will also have reference to UC2 which will have reference to UC1 and thus UC1 could subscribe to some events in WPF-UC.
  2. to use some kind of Mediator and thus we keep the dependency to a minimum.
  3. inject some kind of service which is basically can be Mediator.

I think that approach #2 is the best since I can always move the controls. On the other hand, what kind of cons/pitfalls in this approach can be? What do you think?

If approach #2 is the best is there any library that I can use instead of re-inventing the wheel?

For example, in image below - the TARGET should be updated on WPF UserControl changes. Black - WinForms controls. Red - WPF control.

enter image description here

EpicKip
  • 4,015
  • 1
  • 20
  • 37
theateist
  • 13,879
  • 17
  • 69
  • 109
  • In this situation, it is best to use a `Mediator` pattern. See my [`answer`](http://stackoverflow.com/questions/20868047/one-viewmodel-for-usercontrol-and-window-or-separate-viewmodels) on this subject, may be help. – Anatoliy Nikolaev Feb 24 '14 at 06:09
  • 1
    So, my hunch didn't disappoint me:) I found better mediator implementation, in my opinion - http://www.galasoft.ch/mvvm/. It uses types and not token – theateist Feb 24 '14 at 06:52

1 Answers1

0

I would create delegates in the WPF ViewModel and since it's an instance created by the Winforms module- you can register there for those events, then you can direct other winforms components to act according to your liking because they are also connected to registered component.

Eking
  • 758
  • 8
  • 16