locked
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?

    Thanks,
    Or
    Tuesday, September 1, 2009 10:42 AM

Answers

  • You can apply an style to do this:

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



    http://weblogs.asp.net/marianor/
    • 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