views:

33

answers:

1
+1  Q: 

WPF usercontrol

Hi,

I've got a parent UserControl which has a property which I would like to access from a child usercontrol of the parent.

Is this possible? I'll be doing this through the child control's viewmodel.

Just wanted to get an idea on the best approach to do this.

Thankyou.

+2  A: 

It's not impossible, but it's not the preferred design pattern (at least not one I would happily use).

The easiest way to do this, would be to pass the parent (via reference or interface) to the child (myabe during the new routine).

The way I would do it, is to have the child raise an event (which the parent handles) when the child needs to access the parent's property. Basically, child raises event, parent handles it, by providing the necessary value to the child.

Stephen Wrighton
OK that's fair enough. Thanks for your input.How would I raise an event in the one view model that is then handled in the other? Does the bubbling of events / eventhandlers take care of this?Sorry if this is a basic question!
Jmsparing
Agreed on the design issue.
Henk Holterman