I've got a MVVM WPF app with the TreeView databound to a viewmodel class. It is essentially a file explorer. I want to add the ability to "Add a new folder" to the hierarchy. To achieve the desired functionality what I am trying to do is simply switch the Textblock out for an editable TextBox in my datatemplate. This is what my datatemplate looks like:
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Name="tv_itempanel"
Orientation="Horizontal"
Margin="2">
<Image Source="{Binding Icon}" Margin="4"/>
<TextBlock Name="treeitem_tblock" Margin="4" Text="{Binding Name}"/>
<TextBox Width="200" Visibility="Collapsed" Name="treeitem_tbox"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
The problem is that I cannot modify an individual TreeViewItem since the treeview is databound. Any ideas? Thanks