开发者

Pass values between UserControls

I have a main window, which has four user controls on it. These f开发者_如何学Goive 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.


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).


You can communicate five entities using making delegates.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜