locked
Binding from a template generated item to its parent control's property RRS feed

  • Question

  • hi, group,

    I have a DataTemplate which contains a MenuItem. This DataTemplate is in a Window. Now I declare a Boolean dependency property in the window. How can I bind this Boolean dependency property to the MenuItem's IsEnabled property.

    That menu item is inside a template, is there anyway I can do it?

    Thanks.
    Sunday, September 7, 2008 10:55 PM

Answers

  • You could try a relative binding of the FindAncestor type. It will look up into the visual tree for an element of the specified type.
    Like this:
    {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=MyWindowBooleanProperty}

    hth,
    Marcel
    • Proposed as answer by Jim Zhou - MSFT Thursday, September 11, 2008 2:40 AM
    • Marked as answer by Marco Zhou Friday, September 12, 2008 10:17 AM
    Monday, September 8, 2008 7:09 AM