captncraig
captncraig

Reputation: 23138

Inheriting properties in WPF

I have a custom control that has several text boxes and combo boxes in it. In order for my control to work properly, I need to set the TabIndex on each of the controls to the proper location in the host form. For example, if my control is at TabIndex 2 on the parent form, each control inside it should be set to a TabIndex of 2, and everything works as it should. I am not very good at WPF. My naive solution was to define a public property on my custom control, and have the setter set the TabIndex on each of the subcontrols. I hate this solution.

I'm sure there must be a way to bind properties to whatever is set by the parent control, but I haven't been able to find it.

Upvotes: 0

Views: 792

Answers (1)

Femaref
Femaref

Reputation: 61497

You can use the RelativeSource binding directive. Example:

{Binding RelativeSource={RelativeSource
FindAncestor, AncestorType={x:Type Window}},
Path=Title}

msdn information, wpf cheat sheet.

Upvotes: 2

Related Questions