开发者

Passing params through nested user controls in Silverlight 4

开发者 https://www.devze.com 2023-04-10 12:31 出处:网络
I have a three level of nested user controls in my Silverlght 4 application. the most low level control fires an event with some parameter, then second user control takes the parameter and also fires

I have a three level of nested user controls in my Silverlght 4 application.

the most low level control fires an event with some parameter, then second user control takes the parameter and also fires an event sending parameter to up. Third user controls makes same thing passing parameter to the MainPage. Anyway a have got my parameter but the way I d开发者_如何转开发id it very boring and confusing. Is there any acceptable and easy understanding way to do same thing shorter.

Thanks a lot!


That is the correct way, mainly because any level is replaceable and so should function the same way.

Boring and simple looking are actually good things for code... makes it easier for others to follow.

If you want excitement... I would suggest a career change :)


It all depends on what the event is and what the parameter you are bubbling up contains. If this is purely user-interaction and the visual parent needs to react to your event, then, as HiTech Magic mentions, this is the best way to do it.

Now, if what you are trying to do is actually related with the business logic of the application, then maybe your user control is not best place to handle this event and you may benefit from binding a view model to your user controls and using some kind of event aggregator to broadcast your events.

It may be good for you to add more context to the event your are firing and the parameter which you are bubbling up to the container for you to get additional information which applies to your context.

0

精彩评论

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

关注公众号