1

I have a main window, which has four user controls on it. These five entities need to communicate with each other. Is there an established method for passing values and objects between UserControls?

Edit: I'm familiar with MVVM, but I am asking for solutions outside of that paradigm.

4 Answers 4

2

There are a lot of ways and it depends on what you actual scenario is. The most straight forward one would be to expose public properties and/or events in your UserControls. This is the preferred way if you want to get view specific data across. If your the communication is more model related you should go the route through your ViewModel (and use MVVM).

Generally I think UserControls accessing each other directly is a strong hint toward desgin smell. It is very likely that there is a better aproach for you concrete scenario (Mediator, Eventaggregator, Controller or just the parent control).

2
  • Right - but how do I actually reference the other UserControl to begin with? Do I have to use FindControl?
    – Adam S
    Nov 22, 2010 at 9:06
  • You could have a central (singleton) instance where all UserControls register themselves. But still, it tends to be bad practise when UserControls access each other directly.
    – bitbonk
    Nov 22, 2010 at 12:41
0

You can communicate five entities using making delegates.

0

I think you need to decide upon domain model according to your project requirement and then create classes which represent entities in your model. Then pass objects of this entities as required.

0

There are many ways, one is to use events. There are no "direct" methods, you need to route your values through a form or a model class.

There is an established pattern called MVVM (just google for it) that has a unified way of communicating between different contols, databases, web services, calculations etc. MVVM is not a pattern for communicating between different controls, it is a much larger pattern, but it solves that part too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.