I am currently writing an Folder Browser Dialog in WPF. For displaying the Tree I use an TreeView:
<TreeView Name="FolderView" ItemsSource="{Binding DataTrees}" Grid.Row="0">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Tree}">
<TreeViewItem IsSelected="{Binding IsSelected, Mode=TwoWay}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}" Header="{Binding Name}" HorizontalAlignment="Left"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Currently I have three Problems:
- You can't select an Item in the running Programm
- The Header is about two tabs to the right (not critical but ugly)
- 'IsExpanded' is only set when double clicking an item and not on clicking [+]
I don't know where the Problem is so please comment and I will update my Question!
EDIT: The Itemsource is a List Data Tree Class:
public class DataTree:INotifyPropertyChanged
{
private string path;
private string name;
private ObservableCollection<DataTree> tree;
private bool isSelected;
private bool isExpanded;
}
(simple Code - Without Propertys and Implementation Of INotifyPropertyChanged)
ItemTemplate
without knowing about the internal structure will cause many problems. You should use Expression Blend to view the internal structure of a TreeViewItem. – Aubrette