I have a TreeView that is binded through a HierarchicalDataTemplate
<HierarchicalDataTemplate x:Key="HierachrTree" DataType="{x:Type src:Ordner}" ItemsSource="{Binding UnterOrdner}">
<TextBlock Text="{Binding OrdnerName}"/>
</HierarchicalDataTemplate>
Thats my TreeView:
<TreeView Name="DokumentBrowser" ItemTemplate="{StaticResource HierachrTree}"
Now I want to get the first node and set the IsExpanded Property to false.
I tried it this way
ItemCollection ic = DokumentBrowser.Items;
TreeViewItem tvi = (TreeViewItem)ic.GetItemAt(0);
tvi.IsExpanded = false;
but i can't cast the Object back to a TreeViewItem to get the IsExpanded Property.