Jmsparing
Jmsparing

Reputation: 205

WPF usercontrol

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.

Upvotes: 1

Views: 289

Answers (1)

Stephen Wrighton
Stephen Wrighton

Reputation: 37819

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.

Upvotes: 3

Related Questions