Databinding of properties of containing TreeViewItem RRS feed

  • Question

  • Hi,

    I have a TreeView with a DataTemplate as an ItemTemplate.
    In the render process the template I created is wrapped inside a TreeViewItem (it appears as the Header if I'm not mistaken).
    The objects I insert into the tree contain a property named "IsOpen", which I want to bind to the IsExpanded property of the TreeViewItem that will eventually contain the templated item.
    Is there a way to this?

    Tuesday, September 1, 2009 10:42 AM


  • You can apply an style to do this:

    <TreeView ...>
           <Style TargetType="TreeViewItem">
              <Setter Property="IsExpanded" Value="{Binding IsOpen, Mode=TwoWay}" />

    • Proposed as answer by Hua Chen Wednesday, September 2, 2009 8:04 AM
    • Marked as answer by Hua Chen Tuesday, September 8, 2009 5:15 AM
    Tuesday, September 1, 2009 1:10 PM