Hürol Aslan
Hürol Aslan

Reputation: 181

How to bind to a property of the parent of the item which is the DataContext?

I have a group of controls in a StackPanel container, in a user control, bound to different properties to an item which is the DataContext of the container, set as {Binding MyItem}

How would I bind one of those controls to the logical parent of this MyItem, if MyItem object has a property pointing to its parent?

Upvotes: 0

Views: 92

Answers (2)

digitguy
digitguy

Reputation: 1060

If MyItem has a property pointing to its parent, then you can directly use that property to reference the Parent. Nothing special required for it, like:

{Binding Parent.PropertyName}

(unless I misunderstood the question)

Upvotes: 1

Hürol Aslan
Hürol Aslan

Reputation: 181

It turns out that {Binding Path=Parent.IsEnabled} was enough, provided that the item which is the DataContext has a public property Parent. Probably earlier errors were due to other things.

Upvotes: 1

Related Questions