WPF Access the child control of a user control

This was a question asked here. This is a situation when we’ve created a custom user control and when we add it to a parent user control, we can no longer access the child user control’s UI components.  I’d answered it there, but wanted to add this here as it would be helpful.

Define properties in the child’s class for each of those controls. You will be able to access them from the Parent User Control, assuming you have added the Child User Control within the Parent User Control.

Parent User Control.. SingalData is the child User Contol

<my:C1TabItem Header="Signal"> <local:SignalData Width="1036"></local:SignalData> </my:C1TabItem> 

In the Child User Contorl class, if you have a component named tabProductList you add a property –

public C1.WPF.C1TabControl TabProductList { get { return this.tabProductList; } } 

And finally, from your parent class you can reference it as –

C1TabItem tbItem = (C1TabItem)c1TabControl1.SelectedItem;
SignalData sigInp = (SignalData)tbItem.Content;
if (sigInp.TabProductList.SelectedIndex == 0)

Comment on this:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s